toholio-serialport 0.7.1
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 +20 -0
- data/MANIFEST +11 -0
- data/README +156 -0
- data/extconf.rb +13 -0
- data/lib/serialport.rb +32 -0
- data/serialport.gemspec +24 -0
- data/src/posix_serialport_impl.c +667 -0
- data/src/serialport.c +343 -0
- data/src/serialport.h +64 -0
- data/src/win_serialport_impl.c +616 -0
- data/test/miniterm.rb +25 -0
- metadata +68 -0
data/CHANGELOG
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
0.7.1 => 31/08/2008: Change to gemspec creation and fix posix compilation.
|
2
|
+
|
3
|
+
0.7.0 => 03/07/2008: Major Code Cleanup
|
4
|
+
|
5
|
+
0.6.1 => 25/03/2003: Minor changes
|
6
|
+
|
7
|
+
0.6 => 12/02/2003: Windows support
|
8
|
+
Get/set modem parameters
|
9
|
+
Read and write timeouts
|
10
|
+
Open method
|
11
|
+
|
12
|
+
0.5 => 25/10/2002: Cygwin support
|
13
|
+
|
14
|
+
0.4 => 19/09/2002: Added more serial ports (total of 8 ports)
|
15
|
+
|
16
|
+
0.3 => 15/03/2002: Damn, another bug found
|
17
|
+
|
18
|
+
0.2 => 14/03/2002: A bug fixed (read() was not blocking)
|
19
|
+
|
20
|
+
0.1 => 14/03/2002: First release
|
data/MANIFEST
ADDED
data/README
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
-----Ruby/SerialPort-----
|
2
|
+
|
3
|
+
-- Description --
|
4
|
+
|
5
|
+
Ruby/SerialPort is a Ruby library that provides a class for using
|
6
|
+
RS-232 serial ports. This class also contains low-level functions to
|
7
|
+
check and set the current state of the signals on the line.
|
8
|
+
|
9
|
+
The native Windows version of this library supports Microsoft's Visual C++
|
10
|
+
and Borland's C++ compilers.
|
11
|
+
|
12
|
+
-- Installation --
|
13
|
+
|
14
|
+
This gem is hosted at GitHub. Before you can install this, or any other GitHub gem you must
|
15
|
+
add it as a repository:
|
16
|
+
gem sources -a http://gems.github.com
|
17
|
+
|
18
|
+
Then you can install the gem as normal:
|
19
|
+
sudo gem install toholio-serialport
|
20
|
+
|
21
|
+
-- Testing --
|
22
|
+
|
23
|
+
* test/miniterm.rb
|
24
|
+
|
25
|
+
Ruby's copy of miniterm.c !
|
26
|
+
|
27
|
+
|
28
|
+
-- API --
|
29
|
+
|
30
|
+
**** Class SerialPort, Parent IO ****
|
31
|
+
|
32
|
+
** Class constants **
|
33
|
+
|
34
|
+
VERSION -> aString (this release is "0.6")
|
35
|
+
NONE, HARD, SOFT, SPACE, MARK, EVEN, ODD -> anInteger
|
36
|
+
|
37
|
+
** Class methods **
|
38
|
+
|
39
|
+
* new(port_num [, modem_parameters]) -> aSerialPort
|
40
|
+
* open(port_num [, modem_parameters]) -> aSerialPort
|
41
|
+
* open(port_num [, modem_parameters]) {|aSerialPort| block} ->
|
42
|
+
value of the block
|
43
|
+
|
44
|
+
port_num -> anInteger: port number, 0 for first port which is
|
45
|
+
"/dev/ttyS0" on GNU/Linux and "COM1" on Windows,
|
46
|
+
or aString: file name of the device (example: "/dev/ttyS2")
|
47
|
+
|
48
|
+
Optional modem_parameters:
|
49
|
+
|
50
|
+
baudrate -> anInteger: from 50 to 256000, depends on platform.
|
51
|
+
|
52
|
+
databits -> anInteger: from 5 to 8 (4 is allowed on Windows)
|
53
|
+
|
54
|
+
stopbits -> anInteger: 1 or 2 (1.5 is not supported)
|
55
|
+
|
56
|
+
parity -> anInteger: SerialPort::NONE, SerialPort::EVEN,
|
57
|
+
SerialPort::ODD, SerialPort::MARK, SerialPort::SPACE
|
58
|
+
(MARK and SPACE are not supported on Posix)
|
59
|
+
|
60
|
+
Raise an argError on bad argument.
|
61
|
+
|
62
|
+
SerialPort::new and SerialPort::open without a block return an
|
63
|
+
instance of SerialPort. SerialPort::open with a block passes
|
64
|
+
a SerialPort to the block and closes it when the block exits
|
65
|
+
(like File::open).
|
66
|
+
|
67
|
+
|
68
|
+
** Instance methods **
|
69
|
+
|
70
|
+
* modem_params() -> aHash
|
71
|
+
* modem_params=(aHash) -> aHash
|
72
|
+
* get_modem_params() -> aHash
|
73
|
+
* set_modem_params(aHash) -> aHash
|
74
|
+
* set_modem_params(baudrate [, databits [, stopbits [, parity]]])
|
75
|
+
|
76
|
+
Get and set the modem parameters. Hash keys are "baud", "data_bits",
|
77
|
+
"stop_bits", and "parity" (see above).
|
78
|
+
|
79
|
+
Parameters not present in the hash or set to nil remain unchanged.
|
80
|
+
Default parameter values for the set_modem_params method are:
|
81
|
+
databits = 8, stopbits = 1, parity = (databits == 8 ?
|
82
|
+
SerialPort::NONE : SerialPort::EVEN).
|
83
|
+
|
84
|
+
* baud() -> anInteger
|
85
|
+
* baud=(anInteger) -> anInteger
|
86
|
+
* data_bits() -> 4, 5, 6, 7, or 8
|
87
|
+
* data_bits=(anInteger) -> anInteger
|
88
|
+
* stop_bits() -> 1 or 2
|
89
|
+
* stop_bits=(anInteger) -> anInteger
|
90
|
+
* parity() -> anInteger: SerialPort::NONE, SerialPort::EVEN,
|
91
|
+
SerialPort::ODD, SerialPort::MARK, or SerialPort::SPACE
|
92
|
+
* parity=(anInteger) -> anInteger
|
93
|
+
|
94
|
+
Get and set the corresponding modem parameter.
|
95
|
+
|
96
|
+
* flow_control() -> anInteger
|
97
|
+
* flow_control=(anInteger) -> anInteger
|
98
|
+
|
99
|
+
Get and set the flow control: SerialPort::NONE, SerialPort::HARD,
|
100
|
+
SerialPort::SOFT, or (SerialPort::HARD | SerialPort::SOFT).
|
101
|
+
|
102
|
+
Note: SerialPort::HARD mode is not supported on all platforms.
|
103
|
+
SerialPort::HARD uses RTS/CTS handshaking; DSR/DTR is not
|
104
|
+
supported.
|
105
|
+
|
106
|
+
* read_timeout() -> anInteger
|
107
|
+
* read_timeout=(anInteger) -> anInteger
|
108
|
+
* write_timeout() -> anInteger
|
109
|
+
* write_timeout=(anInteger) -> anInteger
|
110
|
+
|
111
|
+
Get and set timeout values (in milliseconds) for reading and writing.
|
112
|
+
A negative read timeout will return all the available data without
|
113
|
+
waiting, a zero read timeout will not return until at least one
|
114
|
+
byte is available, and a positive read timeout returns when the
|
115
|
+
requested number of bytes is available or the interval between the
|
116
|
+
arrival of two bytes exceeds the timeout value.
|
117
|
+
|
118
|
+
Note: Read timeouts don't mix well with multi-threading.
|
119
|
+
|
120
|
+
Note: Under Posix, write timeouts are not implemented.
|
121
|
+
|
122
|
+
* break(time) -> nil
|
123
|
+
|
124
|
+
Send a break for the given time.
|
125
|
+
|
126
|
+
time -> anInteger: tenths-of-a-second for the break.
|
127
|
+
Note: Under Posix, this value is very approximate.
|
128
|
+
|
129
|
+
* signals() -> aHash
|
130
|
+
|
131
|
+
Return a hash with the state of each line status bit. Keys are
|
132
|
+
"rts", "dtr", "cts", "dsr", "dcd", and "ri".
|
133
|
+
|
134
|
+
Note: Under Windows, the rts and dtr values are not included.
|
135
|
+
|
136
|
+
* rts()
|
137
|
+
* dtr()
|
138
|
+
* cts()
|
139
|
+
* dsr()
|
140
|
+
* dcd()
|
141
|
+
* ri() -> 0 or 1
|
142
|
+
|
143
|
+
* rts=(0 or 1)
|
144
|
+
* dtr=(0 or 1) -> 0 or 1
|
145
|
+
|
146
|
+
Get and set the corresponding line status bit.
|
147
|
+
|
148
|
+
Note: Under Windows, rts() and dtr() are not implemented.
|
149
|
+
|
150
|
+
-- License --
|
151
|
+
|
152
|
+
GPL
|
153
|
+
|
154
|
+
Guillaume Pierronnet <moumar@netcourrier.com>
|
155
|
+
Alan Stern <stern@rowland.harvard.edu>
|
156
|
+
Tobin Richard <tobin.richard@gmail.com>
|
data/extconf.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
|
+
printf("checking for OS... ")
|
4
|
+
STDOUT.flush
|
5
|
+
os = /-([a-z]+)/.match(RUBY_PLATFORM)[1]
|
6
|
+
puts(os)
|
7
|
+
$CFLAGS += " -DOS_#{os.upcase}"
|
8
|
+
|
9
|
+
if !(os == 'mswin' or os == 'bccwin')
|
10
|
+
exit(1) if not have_header("termios.h") or not have_header("unistd.h")
|
11
|
+
end
|
12
|
+
|
13
|
+
create_makefile('serialport','src')
|
data/lib/serialport.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require "serialport.so"
|
2
|
+
|
3
|
+
class SerialPort
|
4
|
+
private_class_method(:create)
|
5
|
+
|
6
|
+
def SerialPort::new(port, *params)
|
7
|
+
sp = create(port)
|
8
|
+
begin
|
9
|
+
sp.set_modem_params(*params)
|
10
|
+
rescue
|
11
|
+
sp.close
|
12
|
+
raise
|
13
|
+
end
|
14
|
+
return sp
|
15
|
+
end
|
16
|
+
|
17
|
+
def SerialPort::open(port, *params)
|
18
|
+
sp = create(port)
|
19
|
+
begin
|
20
|
+
sp.set_modem_params(*params)
|
21
|
+
if (block_given?)
|
22
|
+
yield sp
|
23
|
+
sp.close
|
24
|
+
return nil
|
25
|
+
end
|
26
|
+
rescue
|
27
|
+
sp.close
|
28
|
+
raise
|
29
|
+
end
|
30
|
+
return sp
|
31
|
+
end
|
32
|
+
end
|
data/serialport.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
SPEC = Gem::Specification.new do |s|
|
2
|
+
s.name = 'serialport'
|
3
|
+
s.version = '0.7.1'
|
4
|
+
s.summary = 'Library for using RS-232 serial ports.'
|
5
|
+
s.description = 'SerialPort is a Ruby library that provides a class for using RS-232 serial ports.'
|
6
|
+
s.files = [ 'CHANGELOG',
|
7
|
+
'MANIFEST',
|
8
|
+
'README',
|
9
|
+
'serialport.gemspec',
|
10
|
+
'extconf.rb',
|
11
|
+
'lib/serialport.rb',
|
12
|
+
'src/posix_serialport_impl.c',
|
13
|
+
'src/serialport.c',
|
14
|
+
'src/serialport.h',
|
15
|
+
'src/win_serialport_impl.c' ]
|
16
|
+
s.test_files = [ 'test/miniterm.rb' ]
|
17
|
+
s.extensions << 'extconf.rb'
|
18
|
+
s.has_rdoc = true
|
19
|
+
s.extra_rdoc_files = [ 'README', 'src/serialport.c', 'src/serialport.h' ]
|
20
|
+
s.rdoc_options = [ '--main', 'README' ]
|
21
|
+
s.authors = ['Guillaume Pierronnet', 'Alan Stern', 'Daniel E. Shipton', 'Tobin Richard']
|
22
|
+
s.email = 'tobin.richard@gmail.com'
|
23
|
+
s.homepage = 'http://github.com/toholio/ruby-serialport/'
|
24
|
+
end
|