rubyserial 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d014cad0d8238b82bf39b107e4a68c3ff7e2d16
4
- data.tar.gz: ee8f9b64e23413ebceab097643078f0df1afb2e5
3
+ metadata.gz: 363ae6f9ed63c3a190ef6cfd82af0407dbb40685
4
+ data.tar.gz: 30cac498e9e60636c04cdd1089a0106ab5e58361
5
5
  SHA512:
6
- metadata.gz: c4ca69b2cb366a8a86cfcd898010af66f1fb69c33b4ae53a83d52c9e7cc4e5b56ca45bd3a13bd8bef0c3a511bf7a224a9926a63269c544521d1742a5775c00a3
7
- data.tar.gz: 22216f7ec08c00d115c1760e104304639a5d86ed721db4cc646b844b64954581e92a350df43343e4edef79d863766542e60088150c811f5bdc4a8804985cadfb
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
- However, to run the tests, you must also have the `socat` utility program installed.
52
+ ### Test dependencies
53
53
 
54
- ### Installing socat on OS X
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
- ### Installing socat on Linux
62
+ #### Installing socat on Linux
61
63
 
62
64
  ```
63
65
  sudo apt-get install socat
64
66
  ```
65
67
 
66
- ### Installing socat on Windows
68
+ #### Test on Windows
69
+
70
+ To run the tests on Windows requires com0com which can be downloaded from here:
67
71
 
68
- You might need to build from source... the latest build of socat for Windows is quite old. Get source from here:
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
- CREAD = 0000200
19
+ CSTOPB = 0000100
20
+ CREAD = 0000200
20
21
  CLOCAL = 0004000
21
22
  VMIN = 6
22
- NCCS = 19
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
- CREAD = 0x00000800
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",
@@ -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::BAUDE_RATES[baude_rate] |
121
- RubySerial::Posix::PARITY[parity]
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
 
@@ -1,7 +1,7 @@
1
- # Copyright (c) 2014-2017 The Hybrid Group and Friends
1
+ # Copyright (c) 2014-2018 The Hybrid Group and Friends
2
2
 
3
3
  module RubySerial
4
4
  unless const_defined?('VERSION')
5
- VERSION = "0.5.0"
5
+ VERSION = "0.6.0"
6
6
  end
7
7
  end
@@ -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::ONESTOPBIT
26
- dcb[:parity] = RubySerial::Win32::DCB::NOPARITY
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
@@ -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.5.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: 2017-12-09 00:00:00.000000000 Z
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.4.8
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