hybridgroup-serialport 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,52 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "hybridgroup-serialport"
8
+ s.version = "1.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Guillaume Pierronnet", "Alan Stern", "Daniel E. Shipton", "Tobin Richard", "Hector Parra", "Ryan C. Payne"]
12
+ s.date = "2013-01-13"
13
+ s.description = "Ruby/SerialPort is a Ruby library that provides a class for using RS-232 serial ports."
14
+ s.email = "serialport@hybridgroup.com"
15
+ s.extensions = ["ext/native/extconf.rb", "ext/native/extconf.rb"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE",
18
+ "README"
19
+ ]
20
+ s.files = [
21
+ "CHANGELOG",
22
+ "CHECKLIST",
23
+ "LICENSE",
24
+ "MANIFEST",
25
+ "README",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "ext/native/extconf.rb",
29
+ "ext/native/posix_serialport_impl.c",
30
+ "ext/native/serialport.c",
31
+ "ext/native/serialport.h",
32
+ "ext/native/win_serialport_impl.c",
33
+ "hybridgroup-serialport.gemspec",
34
+ "lib/serialport.rb",
35
+ "test/miniterm.rb",
36
+ "test/set_readtimeout.rb"
37
+ ]
38
+ s.homepage = "http://github.com/hybridgroup/ruby-serialport/"
39
+ s.require_paths = ["lib"]
40
+ s.rubygems_version = "1.8.24"
41
+ s.summary = "Library for using RS-232 serial ports."
42
+
43
+ if s.respond_to? :specification_version then
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
+ else
48
+ end
49
+ else
50
+ end
51
+ end
52
+
data/lib/serialport.rb ADDED
@@ -0,0 +1,55 @@
1
+ if is_osx?
2
+ require 'serialport.bundle'
3
+ else
4
+ require 'serialport.so'
5
+ end
6
+
7
+ class SerialPort
8
+ private_class_method(:create)
9
+
10
+ # Creates a serial port object.
11
+ #
12
+ # <tt>port</tt> may be a port number
13
+ # or the file name of a defice.
14
+ # The number is portable; so 0 is mapped to "COM1" on Windows,
15
+ # "/dev/ttyS0" on Linux, "/dev/cuaa0" on Mac OS X, etc.
16
+ #
17
+ # <tt>params</tt> can be used to configure the serial port.
18
+ # See SerialPort#set_modem_params for details
19
+ def SerialPort::new(port, *params)
20
+ sp = create(port)
21
+ begin
22
+ sp.set_modem_params(*params)
23
+ rescue
24
+ sp.close
25
+ raise
26
+ end
27
+ return sp
28
+ end
29
+
30
+ # This behaves like SerialPort#new, except that you can pass a block
31
+ # to which the new serial port object will be passed. In this case
32
+ # the connection is automaticaly closed when the block has finished.
33
+ def SerialPort::open(port, *params)
34
+ sp = create(port)
35
+ begin
36
+ sp.set_modem_params(*params)
37
+ rescue
38
+ sp.close
39
+ raise
40
+ end
41
+ if (block_given?)
42
+ begin
43
+ yield sp
44
+ ensure
45
+ sp.close
46
+ end
47
+ return nil
48
+ end
49
+ return sp
50
+ end
51
+ end
52
+
53
+ def is_osx?
54
+ return (RUBY_PLATFORM.split("-")[1] == ('darwin')) ? true : false
55
+ end
data/test/miniterm.rb ADDED
@@ -0,0 +1,25 @@
1
+ require "../serialport.so"
2
+
3
+
4
+ if ARGV.size < 4
5
+ STDERR.print <<EOF
6
+ Usage: ruby #{$0} num_port bps nbits stopb
7
+ EOF
8
+ exit(1)
9
+ end
10
+
11
+ sp = SerialPort.new(ARGV[0].to_i, ARGV[1].to_i, ARGV[2].to_i, ARGV[3].to_i, SerialPort::NONE)
12
+
13
+ open("/dev/tty", "r+") { |tty|
14
+ tty.sync = true
15
+ Thread.new {
16
+ while true do
17
+ tty.printf("%c", sp.getc)
18
+ end
19
+ }
20
+ while (l = tty.gets) do
21
+ sp.write(l.sub("\n", "\r"))
22
+ end
23
+ }
24
+
25
+ sp.close
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby
2
+ require "rubygems"
3
+ require "serialport"
4
+
5
+ sp = SerialPort.new("/dev/tty.usbserial", "9600".to_i)
6
+ sp.read_timeout = 100
7
+ sp.close
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hybridgroup-serialport
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Guillaume Pierronnet
9
+ - Alan Stern
10
+ - Daniel E. Shipton
11
+ - Tobin Richard
12
+ - Hector Parra
13
+ - Ryan C. Payne
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+ date: 2013-01-13 00:00:00.000000000 Z
18
+ dependencies: []
19
+ description: Ruby/SerialPort is a Ruby library that provides a class for using RS-232
20
+ serial ports.
21
+ email: serialport@hybridgroup.com
22
+ executables: []
23
+ extensions:
24
+ - ext/native/extconf.rb
25
+ extra_rdoc_files:
26
+ - LICENSE
27
+ - README
28
+ files:
29
+ - CHANGELOG
30
+ - CHECKLIST
31
+ - LICENSE
32
+ - MANIFEST
33
+ - README
34
+ - Rakefile
35
+ - VERSION
36
+ - ext/native/extconf.rb
37
+ - ext/native/posix_serialport_impl.c
38
+ - ext/native/serialport.c
39
+ - ext/native/serialport.h
40
+ - ext/native/win_serialport_impl.c
41
+ - hybridgroup-serialport.gemspec
42
+ - lib/serialport.rb
43
+ - test/miniterm.rb
44
+ - test/set_readtimeout.rb
45
+ homepage: http://github.com/hybridgroup/ruby-serialport/
46
+ licenses: []
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 1.8.24
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Library for using RS-232 serial ports.
69
+ test_files: []