rubyserial 0.5.0 → 0.6.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.
- checksums.yaml +4 -4
- data/README.md +9 -6
- data/lib/rubyserial/linux_constants.rb +8 -2
- data/lib/rubyserial/osx_constants.rb +8 -1
- data/lib/rubyserial/posix.rb +10 -5
- data/lib/rubyserial/version.rb +2 -2
- data/lib/rubyserial/windows.rb +3 -6
- data/lib/rubyserial/windows_constants.rb +14 -0
- data/spec/rubyserial_spec.rb +34 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 363ae6f9ed63c3a190ef6cfd82af0407dbb40685
|
4
|
+
data.tar.gz: 30cac498e9e60636c04cdd1089a0106ab5e58361
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 828439f9181b7d642f297835e1c2f4c7c8d14bd3a99f142e29d46f23e4229ee3d44ad3540f53920f5a7b281c1e04d16c0c2491dfea45cb115fb11e397f391fcc
|
7
|
+
data.tar.gz: 06e3f3263b8a9bebf19dce538387b5518adc40d61c2ffa48175f1f489ace10b06c25b8652330f985608ae57887a3b936b14ff894a7970ebe54276ed85c176936
|
data/README.md
CHANGED
@@ -49,25 +49,28 @@ A wrapper error type that returns the underlying system error code and inherits
|
|
49
49
|
|
50
50
|
The test suite is written using rspec, just use the `rspec` command.
|
51
51
|
|
52
|
-
|
52
|
+
### Test dependencies
|
53
53
|
|
54
|
-
|
54
|
+
To run the tests on OS X and Linux, you must also have the `socat` utility program installed.
|
55
|
+
|
56
|
+
#### Installing socat on OS X
|
55
57
|
|
56
58
|
```
|
57
59
|
brew install socat
|
58
60
|
```
|
59
61
|
|
60
|
-
|
62
|
+
#### Installing socat on Linux
|
61
63
|
|
62
64
|
```
|
63
65
|
sudo apt-get install socat
|
64
66
|
```
|
65
67
|
|
66
|
-
|
68
|
+
#### Test on Windows
|
69
|
+
|
70
|
+
To run the tests on Windows requires com0com which can be downloaded from here:
|
67
71
|
|
68
|
-
|
72
|
+
https://github.com/hybridgroup/rubyserial/raw/appveyor_deps/setup_com0com_W7_x64_signed.exe
|
69
73
|
|
70
|
-
http://www.dest-unreach.org/socat/download/
|
71
74
|
|
72
75
|
## License
|
73
76
|
|
@@ -16,10 +16,11 @@ module RubySerial
|
|
16
16
|
IGNPAR = 0000004
|
17
17
|
PARENB = 0000400
|
18
18
|
PARODD = 0001000
|
19
|
-
|
19
|
+
CSTOPB = 0000100
|
20
|
+
CREAD = 0000200
|
20
21
|
CLOCAL = 0004000
|
21
22
|
VMIN = 6
|
22
|
-
NCCS =
|
23
|
+
NCCS = 32
|
23
24
|
|
24
25
|
DATA_BITS = {
|
25
26
|
5 => 0000000,
|
@@ -68,6 +69,11 @@ module RubySerial
|
|
68
69
|
:odd => PARENB | PARODD,
|
69
70
|
}
|
70
71
|
|
72
|
+
STOPBITS = {
|
73
|
+
1 => 0x00000000,
|
74
|
+
2 => CSTOPB
|
75
|
+
}
|
76
|
+
|
71
77
|
ERROR_CODES = {
|
72
78
|
1 => "EPERM",
|
73
79
|
2 => "ENOENT",
|
@@ -16,7 +16,9 @@ module RubySerial
|
|
16
16
|
VMIN = 16
|
17
17
|
VTIME = 17
|
18
18
|
CLOCAL = 0x00008000
|
19
|
-
|
19
|
+
CSTOPB = 0x00000400
|
20
|
+
CREAD = 0x00000800
|
21
|
+
CCTS_OFLOW = 0x00010000 # Clearing this disables RTS AND CTS.
|
20
22
|
TCSANOW = 0
|
21
23
|
NCCS = 20
|
22
24
|
|
@@ -59,6 +61,11 @@ module RubySerial
|
|
59
61
|
:odd => PARENB | PARODD,
|
60
62
|
}
|
61
63
|
|
64
|
+
STOPBITS = {
|
65
|
+
1 => 0x00000000,
|
66
|
+
2 => CSTOPB
|
67
|
+
}
|
68
|
+
|
62
69
|
ERROR_CODES = {
|
63
70
|
1 => "EPERM",
|
64
71
|
2 => "ENOENT",
|
data/lib/rubyserial/posix.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Copyright (c) 2014-2016 The Hybrid Group
|
2
2
|
|
3
3
|
class Serial
|
4
|
-
def initialize(address, baude_rate=9600, data_bits=8, parity=:none)
|
4
|
+
def initialize(address, baude_rate=9600, data_bits=8, parity=:none, stop_bits=1)
|
5
5
|
file_opts = RubySerial::Posix::O_RDWR | RubySerial::Posix::O_NOCTTY | RubySerial::Posix::O_NONBLOCK
|
6
6
|
@fd = RubySerial::Posix.open(address, file_opts)
|
7
7
|
|
@@ -21,7 +21,7 @@ class Serial
|
|
21
21
|
raise RubySerial::Error, RubySerial::Posix::ERROR_CODES[FFI.errno]
|
22
22
|
end
|
23
23
|
|
24
|
-
@config = build_config(baude_rate, data_bits, parity)
|
24
|
+
@config = build_config(baude_rate, data_bits, parity, stop_bits)
|
25
25
|
|
26
26
|
err = RubySerial::Posix.tcsetattr(@fd, RubySerial::Posix::TCSANOW, @config)
|
27
27
|
if err == -1
|
@@ -108,7 +108,7 @@ class Serial
|
|
108
108
|
bytes.map { |e| e.chr }.join
|
109
109
|
end
|
110
110
|
|
111
|
-
def build_config(baude_rate, data_bits, parity)
|
111
|
+
def build_config(baude_rate, data_bits, parity, stop_bits)
|
112
112
|
config = RubySerial::Posix::Termios.new
|
113
113
|
|
114
114
|
config[:c_iflag] = RubySerial::Posix::IGNPAR
|
@@ -117,8 +117,13 @@ class Serial
|
|
117
117
|
config[:c_cflag] = RubySerial::Posix::DATA_BITS[data_bits] |
|
118
118
|
RubySerial::Posix::CREAD |
|
119
119
|
RubySerial::Posix::CLOCAL |
|
120
|
-
RubySerial::Posix::
|
121
|
-
RubySerial::Posix::
|
120
|
+
RubySerial::Posix::PARITY[parity] |
|
121
|
+
RubySerial::Posix::STOPBITS[stop_bits]
|
122
|
+
|
123
|
+
# Masking in baud rate on OS X would corrupt the settings.
|
124
|
+
if RubySerial::ON_LINUX
|
125
|
+
config[:c_cflag] = config[:c_cflag] | RubySerial::Posix::BAUDE_RATES[baude_rate]
|
126
|
+
end
|
122
127
|
|
123
128
|
config[:cc_c][RubySerial::Posix::VMIN] = 0
|
124
129
|
|
data/lib/rubyserial/version.rb
CHANGED
data/lib/rubyserial/windows.rb
CHANGED
@@ -1,10 +1,7 @@
|
|
1
1
|
# Copyright (c) 2014-2016 The Hybrid Group
|
2
2
|
|
3
3
|
class Serial
|
4
|
-
def initialize(address, baude_rate=9600, data_bits=8, parity=:none)
|
5
|
-
if parity != :none
|
6
|
-
warn "warning: parity #{parity} is not supported on Windows. Ignoring."
|
7
|
-
end
|
4
|
+
def initialize(address, baude_rate=9600, data_bits=8, parity=:none, stop_bits=1)
|
8
5
|
file_opts = RubySerial::Win32::GENERIC_READ | RubySerial::Win32::GENERIC_WRITE
|
9
6
|
@fd = RubySerial::Win32.CreateFileA("\\\\.\\#{address}", file_opts, 0, nil, RubySerial::Win32::OPEN_EXISTING, 0, nil)
|
10
7
|
err = FFI.errno
|
@@ -22,8 +19,8 @@ class Serial
|
|
22
19
|
end
|
23
20
|
dcb[:baudrate] = baude_rate
|
24
21
|
dcb[:bytesize] = data_bits
|
25
|
-
dcb[:stopbits] = RubySerial::Win32::DCB::
|
26
|
-
dcb[:parity] = RubySerial::Win32::DCB::
|
22
|
+
dcb[:stopbits] = RubySerial::Win32::DCB::STOPBITS[stop_bits]
|
23
|
+
dcb[:parity] = RubySerial::Win32::DCB::PARITY[parity]
|
27
24
|
err = RubySerial::Win32.SetCommState @fd, dcb
|
28
25
|
if err == 0
|
29
26
|
raise RubySerial::Error, RubySerial::Win32::ERROR_CODES[FFI.errno]
|
@@ -252,7 +252,21 @@ module RubySerial
|
|
252
252
|
# uint32 fDummy2 :17;
|
253
253
|
Sizeof = 28
|
254
254
|
ONESTOPBIT = 0
|
255
|
+
TWOSTOPBITS = 2
|
256
|
+
|
257
|
+
STOPBITS = {
|
258
|
+
1 => ONESTOPBIT,
|
259
|
+
2 => TWOSTOPBITS
|
260
|
+
}
|
261
|
+
|
255
262
|
NOPARITY = 0
|
263
|
+
ODDPARITY = 1
|
264
|
+
EVENPARITY = 2
|
265
|
+
PARITY = {
|
266
|
+
:none => NOPARITY,
|
267
|
+
:odd => ODDPARITY,
|
268
|
+
:even => EVENPARITY
|
269
|
+
}
|
256
270
|
end
|
257
271
|
|
258
272
|
class CommTimeouts < FFI::Struct
|
data/spec/rubyserial_spec.rb
CHANGED
@@ -148,5 +148,39 @@ describe "rubyserial" do
|
|
148
148
|
@sp.write("Hello!\n")
|
149
149
|
expect(@sp2.gets).to eql("Hello!\n")
|
150
150
|
end
|
151
|
+
|
152
|
+
it 'should accept 1 stop bit' do
|
153
|
+
@sp2.close
|
154
|
+
@sp.close
|
155
|
+
@sp2 = Serial.new(@ports[0], 19200, 8, :none, 1)
|
156
|
+
@sp = Serial.new(@ports[1], 19200, 8, :none, 1)
|
157
|
+
@sp.write("Hello!\n")
|
158
|
+
expect(@sp2.gets).to eql("Hello!\n")
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'should accept 2 stop bits' do
|
162
|
+
@sp2.close
|
163
|
+
@sp.close
|
164
|
+
@sp2 = Serial.new(@ports[0], 19200, 8, :none, 2)
|
165
|
+
@sp = Serial.new(@ports[1], 19200, 8, :none, 2)
|
166
|
+
@sp.write("Hello!\n")
|
167
|
+
expect(@sp2.gets).to eql("Hello!\n")
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'should set baude rate, check #46 fixed' do
|
171
|
+
skip 'Not a bug on Windows' if RubySerial::ON_WINDOWS
|
172
|
+
@sp.close
|
173
|
+
rate = 600
|
174
|
+
@sp = Serial.new(@ports[1], rate)
|
175
|
+
fd = @sp.instance_variable_get(:@fd)
|
176
|
+
module RubySerial
|
177
|
+
module Posix
|
178
|
+
attach_function :tcgetattr, [ :int, RubySerial::Posix::Termios ], :int, blocking: true
|
179
|
+
end
|
180
|
+
end
|
181
|
+
termios = RubySerial::Posix::Termios.new
|
182
|
+
RubySerial::Posix::tcgetattr(fd, termios)
|
183
|
+
expect(termios[:c_ispeed]).to eql(RubySerial::Posix::BAUDE_RATES[rate])
|
184
|
+
end
|
151
185
|
end
|
152
186
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyserial
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrian Zankich
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2018-09-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: ffi
|
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
76
|
version: '0'
|
77
77
|
requirements: []
|
78
78
|
rubyforge_project:
|
79
|
-
rubygems_version: 2.
|
79
|
+
rubygems_version: 2.6.11
|
80
80
|
signing_key:
|
81
81
|
specification_version: 4
|
82
82
|
summary: FFI Ruby library for RS-232 serial port communication
|