serialport 1.0.4 → 1.1.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.
- data/CHANGELOG +46 -43
- data/CHECKLIST +11 -0
- data/LICENSE +339 -339
- data/MANIFEST +12 -12
- data/README +153 -157
- data/Rakefile +33 -24
- data/VERSION +1 -1
- data/ext/native/extconf.rb +13 -14
- data/ext/native/posix_serialport_impl.c +733 -688
- data/ext/native/serialport.c +492 -492
- data/ext/native/serialport.h +99 -99
- data/ext/native/win_serialport_impl.c +623 -627
- data/lib/serialport.rb +47 -47
- data/serialport.gemspec +52 -59
- data/test/miniterm.rb +25 -25
- data/test/set_readtimeout.rb +7 -7
- metadata +11 -16
- data/.gitignore +0 -10
data/lib/serialport.rb
CHANGED
@@ -1,47 +1,47 @@
|
|
1
|
-
require 'serialport.so'
|
2
|
-
|
3
|
-
class SerialPort
|
4
|
-
private_class_method(:create)
|
5
|
-
|
6
|
-
# Creates a serial port object.
|
7
|
-
#
|
8
|
-
# <tt>port</tt> may be a port number
|
9
|
-
# or the file name of a defice.
|
10
|
-
# The number is portable; so 0 is mapped to "COM1" on Windows,
|
11
|
-
# "/dev/ttyS0" on Linux, "/dev/cuaa0" on Mac OS X, etc.
|
12
|
-
#
|
13
|
-
# <tt>params</tt> can be used to configure the serial port.
|
14
|
-
# See SerialPort#set_modem_params for details
|
15
|
-
def SerialPort::new(port, *params)
|
16
|
-
sp = create(port)
|
17
|
-
begin
|
18
|
-
sp.set_modem_params(*params)
|
19
|
-
rescue
|
20
|
-
sp.close
|
21
|
-
raise
|
22
|
-
end
|
23
|
-
return sp
|
24
|
-
end
|
25
|
-
|
26
|
-
# This behaves like SerialPort#new, except that you can pass a block
|
27
|
-
# to which the new serial port object will be passed. In this case
|
28
|
-
# the connection is automaticaly closed when the block has finished.
|
29
|
-
def SerialPort::open(port, *params)
|
30
|
-
sp = create(port)
|
31
|
-
begin
|
32
|
-
sp.set_modem_params(*params)
|
33
|
-
rescue
|
34
|
-
sp.close
|
35
|
-
raise
|
36
|
-
end
|
37
|
-
if (block_given?)
|
38
|
-
begin
|
39
|
-
yield sp
|
40
|
-
ensure
|
41
|
-
sp.close
|
42
|
-
end
|
43
|
-
return nil
|
44
|
-
end
|
45
|
-
return sp
|
46
|
-
end
|
47
|
-
end
|
1
|
+
require 'serialport.so'
|
2
|
+
|
3
|
+
class SerialPort
|
4
|
+
private_class_method(:create)
|
5
|
+
|
6
|
+
# Creates a serial port object.
|
7
|
+
#
|
8
|
+
# <tt>port</tt> may be a port number
|
9
|
+
# or the file name of a defice.
|
10
|
+
# The number is portable; so 0 is mapped to "COM1" on Windows,
|
11
|
+
# "/dev/ttyS0" on Linux, "/dev/cuaa0" on Mac OS X, etc.
|
12
|
+
#
|
13
|
+
# <tt>params</tt> can be used to configure the serial port.
|
14
|
+
# See SerialPort#set_modem_params for details
|
15
|
+
def SerialPort::new(port, *params)
|
16
|
+
sp = create(port)
|
17
|
+
begin
|
18
|
+
sp.set_modem_params(*params)
|
19
|
+
rescue
|
20
|
+
sp.close
|
21
|
+
raise
|
22
|
+
end
|
23
|
+
return sp
|
24
|
+
end
|
25
|
+
|
26
|
+
# This behaves like SerialPort#new, except that you can pass a block
|
27
|
+
# to which the new serial port object will be passed. In this case
|
28
|
+
# the connection is automaticaly closed when the block has finished.
|
29
|
+
def SerialPort::open(port, *params)
|
30
|
+
sp = create(port)
|
31
|
+
begin
|
32
|
+
sp.set_modem_params(*params)
|
33
|
+
rescue
|
34
|
+
sp.close
|
35
|
+
raise
|
36
|
+
end
|
37
|
+
if (block_given?)
|
38
|
+
begin
|
39
|
+
yield sp
|
40
|
+
ensure
|
41
|
+
sp.close
|
42
|
+
end
|
43
|
+
return nil
|
44
|
+
end
|
45
|
+
return sp
|
46
|
+
end
|
47
|
+
end
|
data/serialport.gemspec
CHANGED
@@ -1,59 +1,52 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "1.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 =
|
13
|
-
s.description =
|
14
|
-
s.email =
|
15
|
-
s.extensions = ["ext/native/extconf.rb", "ext/native/extconf.rb"]
|
16
|
-
s.extra_rdoc_files = [
|
17
|
-
"
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
"
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
s.
|
40
|
-
s.
|
41
|
-
s.
|
42
|
-
|
43
|
-
s.
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
54
|
-
else
|
55
|
-
end
|
56
|
-
else
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
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 = "serialport"
|
8
|
+
s.version = "1.1.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 = "2012-05-26"
|
13
|
+
s.description = "Ruby/SerialPort is a Ruby library that provides a class for using RS-232 serial ports."
|
14
|
+
s.email = "hector@hectorparra.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
|
+
"lib/serialport.rb",
|
34
|
+
"serialport.gemspec",
|
35
|
+
"test/miniterm.rb",
|
36
|
+
"test/set_readtimeout.rb"
|
37
|
+
]
|
38
|
+
s.homepage = "http://github.com/hparra/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/test/miniterm.rb
CHANGED
@@ -1,25 +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
|
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
|
data/test/set_readtimeout.rb
CHANGED
@@ -1,7 +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
|
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
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serialport
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 19
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 1.0.4
|
10
|
+
version: 1.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Guillaume Pierronnet
|
@@ -20,8 +20,7 @@ autorequire:
|
|
20
20
|
bindir: bin
|
21
21
|
cert_chain: []
|
22
22
|
|
23
|
-
date:
|
24
|
-
default_executable:
|
23
|
+
date: 2012-05-26 00:00:00 Z
|
25
24
|
dependencies: []
|
26
25
|
|
27
26
|
description: Ruby/SerialPort is a Ruby library that provides a class for using RS-232 serial ports.
|
@@ -30,14 +29,12 @@ executables: []
|
|
30
29
|
|
31
30
|
extensions:
|
32
31
|
- ext/native/extconf.rb
|
33
|
-
- ext/native/extconf.rb
|
34
32
|
extra_rdoc_files:
|
35
|
-
- CHANGELOG
|
36
33
|
- LICENSE
|
37
34
|
- README
|
38
35
|
files:
|
39
|
-
- .gitignore
|
40
36
|
- CHANGELOG
|
37
|
+
- CHECKLIST
|
41
38
|
- LICENSE
|
42
39
|
- MANIFEST
|
43
40
|
- README
|
@@ -52,13 +49,12 @@ files:
|
|
52
49
|
- serialport.gemspec
|
53
50
|
- test/miniterm.rb
|
54
51
|
- test/set_readtimeout.rb
|
55
|
-
has_rdoc: true
|
56
52
|
homepage: http://github.com/hparra/ruby-serialport/
|
57
53
|
licenses: []
|
58
54
|
|
59
55
|
post_install_message:
|
60
|
-
rdoc_options:
|
61
|
-
|
56
|
+
rdoc_options: []
|
57
|
+
|
62
58
|
require_paths:
|
63
59
|
- lib
|
64
60
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -82,10 +78,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
78
|
requirements: []
|
83
79
|
|
84
80
|
rubyforge_project:
|
85
|
-
rubygems_version: 1.
|
81
|
+
rubygems_version: 1.8.24
|
86
82
|
signing_key:
|
87
83
|
specification_version: 3
|
88
84
|
summary: Library for using RS-232 serial ports.
|
89
|
-
test_files:
|
90
|
-
|
91
|
-
- test/set_readtimeout.rb
|
85
|
+
test_files: []
|
86
|
+
|