rubyserial 0.3.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d2f04ee25b99a43446963e07bc51a82bab7fc6b2
4
- data.tar.gz: 0df2b7cbbde4edc8f268d1b78c744ff88d608a45
3
+ metadata.gz: bf9ebb88fab33dab5ecbab092ef61a44e79f68f9
4
+ data.tar.gz: 8b87a90c0ea75207abd1a42dc39eb03eed3ed17c
5
5
  SHA512:
6
- metadata.gz: 764b79276ea5b8d352dda64d5ade0f9a0b260af4c45c845c45addd8c184b760e10e0eba0cd9ab2e2648fae84264a8c050c462e4702f7a45dd72ca0993e34b8d0
7
- data.tar.gz: 510df41b207862690ce47456763ea0a8bcfeb0ccf19b7989e7defaeb52f98ed4ed0823468854e6483b82182b3abc7060c58fe81ee99cb27cebbcd835af470267
6
+ metadata.gz: f5e575bf1e75f67c330a72429bb6fa6e2140b03d6af89225eeaeb8258bd36e4b7109340d092eff63fe89587859d299335726075f47fd873fe458f8de99b7a983
7
+ data.tar.gz: c6e97c61f1a61ea9f531d056a5b827ce41bd31d1eafba2bfc55d4a1e6919490a765acffb067a0d48457b30d61904da017f1bcf6e36afbe29364d20d48809d4ff
data/.travis.yml CHANGED
@@ -1,19 +1,18 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
- - 2.0
5
- - 2.1
3
+ - 2.3.1
6
4
  - 2.2
5
+ - 2.1
6
+ - jruby-9.1.2.0
7
+ - rbx-2
7
8
  - ruby-head
8
- - jruby
9
9
  - jruby-head
10
- - rbx-2
11
10
  matrix:
12
11
  allow_failures:
13
12
  - rvm: jruby-head
14
13
  - rvm: ruby-head
15
14
  before_install:
16
- - gem update bundler
15
+ - gem query -i -n ^bundler$ -v'>=1.12.5' >/dev/null || gem install bundler
17
16
  install:
18
17
  - sudo apt-get update && sudo apt-get install --force-yes socat
19
18
  script:
data/README.md CHANGED
@@ -18,7 +18,9 @@ The interface to RubySerial should be (mostly) compatible with other Ruby serial
18
18
 
19
19
  ```ruby
20
20
  require 'rubyserial'
21
+ serialport = Serial.new '/dev/ttyACM0' # Defaults to 9600 baud, 8 data bits, and no parity
21
22
  serialport = Serial.new '/dev/ttyACM0', 57600
23
+ serialport = Serial.new '/dev/ttyACM0', 19200, 8, :even
22
24
  ```
23
25
 
24
26
  ## Methods
data/appveyor.yml CHANGED
@@ -20,7 +20,9 @@ test_script:
20
20
 
21
21
  environment:
22
22
  matrix:
23
- - ruby_version: "200-x64"
24
- - ruby_version: "21-x64"
23
+ - ruby_version: 22
24
+ - ruby_version: 21
25
+ - ruby_version: 200
26
+ - ruby_version: 193
25
27
 
26
28
  build: off
data/lib/rubyserial.rb CHANGED
@@ -2,18 +2,19 @@
2
2
 
3
3
  require 'rbconfig'
4
4
  require 'ffi'
5
- include RbConfig
6
5
 
7
6
  module RubySerial
7
+ ON_WINDOWS = RbConfig::CONFIG['host_os'] =~ /mswin|windows|mingw/i
8
+ ON_LINUX = RbConfig::CONFIG['host_os'] =~ /linux/i
8
9
  class Exception < Exception
9
10
  end
10
11
  end
11
12
 
12
- if CONFIG['host_os'] =~ /mswin|windows|mingw/i
13
+ if RubySerial::ON_WINDOWS
13
14
  require 'rubyserial/windows_constants'
14
15
  require 'rubyserial/windows'
15
16
  else
16
- if CONFIG['host_os'] =~ /linux/i
17
+ if RubySerial::ON_LINUX
17
18
  require 'rubyserial/linux_constants'
18
19
  else
19
20
  require 'rubyserial/osx_constants'
@@ -14,6 +14,8 @@ module RubySerial
14
14
  TCSANOW = 0
15
15
  TCSETS = 0x5402
16
16
  IGNPAR = 0000004
17
+ PARENB = 0000400
18
+ PARODD = 0001000
17
19
  CREAD = 0000200
18
20
  CLOCAL = 0004000
19
21
  VMIN = 6
@@ -60,6 +62,12 @@ module RubySerial
60
62
  4000000 => 0010017
61
63
  }
62
64
 
65
+ PARITY = {
66
+ :none => 0000000,
67
+ :even => PARENB,
68
+ :odd => PARENB | PARODD,
69
+ }
70
+
63
71
  ERROR_CODES = {
64
72
  1 => "EPERM",
65
73
  2 => "ENOENT",
@@ -11,6 +11,8 @@ module RubySerial
11
11
  F_GETFL = 3
12
12
  F_SETFL = 4
13
13
  IGNPAR = 0x00000004
14
+ PARENB = 0x00001000
15
+ PARODD = 0x00002000
14
16
  VMIN = 16
15
17
  VTIME = 17
16
18
  CLOCAL = 0x00008000
@@ -51,6 +53,12 @@ module RubySerial
51
53
  230400 => 230400
52
54
  }
53
55
 
56
+ PARITY = {
57
+ :none => 0x00000000,
58
+ :even => PARENB,
59
+ :odd => PARENB | PARODD,
60
+ }
61
+
54
62
  ERROR_CODES = {
55
63
  1 => "EPERM",
56
64
  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)
4
+ def initialize(address, baude_rate=9600, data_bits=8, parity=:none)
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::Exception, RubySerial::Posix::ERROR_CODES[FFI.errno]
22
22
  end
23
23
 
24
- @config = build_config(baude_rate, data_bits)
24
+ @config = build_config(baude_rate, data_bits, parity)
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)
111
+ def build_config(baude_rate, data_bits, parity)
112
112
  config = RubySerial::Posix::Termios.new
113
113
 
114
114
  config[:c_iflag] = RubySerial::Posix::IGNPAR
@@ -117,7 +117,8 @@ 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]
120
+ RubySerial::Posix::BAUDE_RATES[baude_rate] |
121
+ RubySerial::Posix::PARITY[parity]
121
122
 
122
123
  config[:cc_c][RubySerial::Posix::VMIN] = 0
123
124
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RubySerial
4
4
  unless const_defined?('VERSION')
5
- VERSION = "0.3.0"
5
+ VERSION = "0.4.0"
6
6
  end
7
7
  end
@@ -1,7 +1,10 @@
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)
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
5
8
  file_opts = RubySerial::Win32::GENERIC_READ | RubySerial::Win32::GENERIC_WRITE
6
9
  @fd = RubySerial::Win32.CreateFileA("\\\\.\\#{address}", file_opts, 0, nil, RubySerial::Win32::OPEN_EXISTING, 0, nil)
7
10
  err = FFI.errno
@@ -3,8 +3,7 @@ require 'rubyserial'
3
3
  describe "rubyserial" do
4
4
  before do
5
5
  @ports = []
6
- require 'rbconfig'
7
- if RbConfig::CONFIG['host_os'] =~ /mswin|windows|mingw/i
6
+ if RubySerial::ON_WINDOWS
8
7
  # NOTE: Tests on windows require com0com
9
8
  # https://github.com/hybridgroup/rubyserial/raw/appveyor_deps/setup_com0com_W7_x64_signed.exe
10
9
  @ports[0] = "\\\\.\\CNCA0"
@@ -130,4 +129,24 @@ describe "rubyserial" do
130
129
  expect(@sp2.gets('')).to eql("Something \n Something else \n\n")
131
130
  end
132
131
  end
132
+
133
+ describe 'config' do
134
+ it 'should accept EVEN parity' do
135
+ @sp2.close
136
+ @sp.close
137
+ @sp2 = Serial.new(@ports[0], 19200, 8, :even)
138
+ @sp = Serial.new(@ports[1], 19200, 8, :even)
139
+ @sp.write("Hello!\n")
140
+ expect(@sp2.gets).to eql("Hello!\n")
141
+ end
142
+
143
+ it 'should accept ODD parity' do
144
+ @sp2.close
145
+ @sp.close
146
+ @sp2 = Serial.new(@ports[0], 19200, 8, :odd)
147
+ @sp = Serial.new(@ports[1], 19200, 8, :odd)
148
+ @sp.write("Hello!\n")
149
+ expect(@sp2.gets).to eql("Hello!\n")
150
+ end
151
+ end
133
152
  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.3.0
4
+ version: 0.4.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: 2016-05-21 00:00:00.000000000 Z
13
+ date: 2016-07-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: ffi