rs_232 2.0.5 → 2.0.7

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: 02b47c417da4c2ac9d676ae91bc548663524bfae
4
- data.tar.gz: c96c66b86fd82adc7096ac0c3a3d7e095492ed4b
3
+ metadata.gz: 0b19997f03f98c0496bda194020c1917d87bc185
4
+ data.tar.gz: 0bbca6b87935a65a3eb780b54eaccc8c0c988f00
5
5
  SHA512:
6
- metadata.gz: e42240f209342321179a8fe9fb55212d43b87d935f34ea57945efc14173b0fb0b8810b33431e9d36379de5691201c69c0517a5de479ab49971e7240b431280b1
7
- data.tar.gz: 2fafebd69fc832811a32165188b1c723480a6079cd40629303ca2b27498611315211cdbb4f2f1381ed54da9a634d488501643ea663d4f5a0c070156d62293545
6
+ metadata.gz: a683dfd3c2aa42c3399f6fa520059657a6baf76e0299c588588fa10b59b3a70eec4ffe57afed94d0391d8dc6bb3dd38665a9f186e5260eb8592f24fc1c902ece
7
+ data.tar.gz: 4c1167898a7ce5db45fdc7a4e666fc4d3fee19b0693e6e3c566ea9696dbbcef73217c0d4936cbd498b7687e8a3b67d01f82700c77908d745d30a83d2083d26c2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rs_232 (2.0.5)
4
+ rs_232 (2.0.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -47,11 +47,11 @@ PLATFORMS
47
47
  ruby
48
48
 
49
49
  DEPENDENCIES
50
- bundler (>= 1.5.3)
51
- cucumber (>= 1.3.11)
52
- pry (>= 0.9.12.6)
53
- rake (>= 10.1.1)
54
- rake-compiler (>= 0.9.2)
50
+ bundler (~> 1.5, >= 1.5.3)
51
+ cucumber (~> 1.3, >= 1.3.11)
52
+ pry (~> 0.9, >= 0.9.12.6)
53
+ rake (~> 10.1, >= 10.1.1)
54
+ rake-compiler (~> 0.9, >= 0.9.2)
55
55
  rs_232!
56
- rspec (>= 2.14.1)
57
- simplecov (>= 0.8.2)
56
+ rspec (~> 2.14, >= 2.14.1)
57
+ simplecov (~> 0.8, >= 0.8.2)
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # Rs232
2
2
 
3
- Native implementation of the Rs-232 conneciton type
3
+ This is a rs-232 implementation as a Ruby extension in C.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  Add this line to your application's Gemfile:
8
8
 
9
- gem 'ruby-rs-232'
9
+ gem 'rs_232'
10
10
 
11
11
  And then execute:
12
12
 
@@ -14,51 +14,192 @@ And then execute:
14
14
 
15
15
  Or install it yourself as:
16
16
 
17
- $ gem install ruby-rs-232
17
+ $ gem install rs_232
18
18
 
19
19
  ## Usage
20
20
 
21
21
  ```ruby
22
+
22
23
  require "rs_232"
23
24
 
24
- class Serial
25
- attr_reader :interface
26
- include CommPort
27
-
28
- # == constructor with default params
29
- # by default port will be configured with:
30
- #
31
- # @baud_rate = 115200 # BAUD_115200
32
- # @data_bits = 8 # DATA_BITS_8
33
- # @parity = 0 # PAR_NONE
34
- # @stop_bits = 1 # STOP_1
35
- # @flow_control = 0 # FLOW_OFF
36
- #
37
- #
38
- def initialize(port)
39
- @interface ||= Rs232.new(port)
40
- end
41
-
42
- #
43
- # other adapter methods here ...
44
- #
45
- # adapter example placed in the lib folder
46
- #
47
-
48
- end
49
-
50
- #== Windows
51
-
52
- @adapter = Serial.new("COM3")
53
-
54
- #== Linux
55
-
56
- @adapter = Serial.new("/dev/tty.usb00000")
57
-
58
- #== Darwin
59
-
60
- @adapter = Serial.new("/dev/ttyACM0")
61
- ```
25
+ ###### Windows
26
+
27
+ @adapter = Rs232::Adapter.new("COM3")
28
+
29
+ ###### Linux
30
+
31
+ @adapter = Rs232::Adapter.new("/dev/tty.usb00000")
32
+
33
+ ###### Darwin
34
+
35
+ @adapter = Rs232::Adapter.new("/dev/ttyACM0")
36
+
37
+ ###### or implement your own adapter, here is example
38
+
39
+ class MyAdapter
40
+ attr_reader :interface
41
+
42
+ # == Top level module ::CommPort constants
43
+ #
44
+ # :VERSION,
45
+ #
46
+ # :BAUD_110,
47
+ # :BAUD_300,
48
+ # :BAUD_600,
49
+ # :BAUD_1200,
50
+ # :BAUD_2400,
51
+ # :BAUD_4800,
52
+ # :BAUD_9600,
53
+ # :BAUD_19200,
54
+ # :BAUD_38400,
55
+ # :BAUD_57600,
56
+ # :BAUD_115200,
57
+ #
58
+ # :DATA_BITS_5,
59
+ # :DATA_BITS_6,
60
+ # :DATA_BITS_7,
61
+ # :DATA_BITS_8,
62
+ #
63
+ # :PAR_NONE,
64
+ # :PAR_ODD,
65
+ # :PAR_EVEN,
66
+ #
67
+ # :STOP_BITS_1,
68
+ # :STOP_BITS_3,
69
+ #
70
+ # :FLOW_OFF,
71
+ # :FLOW_HARDWARE,
72
+ # :FLOW_XONXOFF,
73
+ #
74
+ # :Impl
75
+ #
76
+
77
+
78
+ # == constructor with default params
79
+ #
80
+ def initialize(port)
81
+ @interface = CommPort::Rs232.new(port)
82
+ connect
83
+ end
84
+
85
+ # Open and configure interface
86
+ #
87
+ # @return [Bool]
88
+ #
89
+ def connect
90
+ @interface.open
91
+
92
+ @interface.baud_rate = CommPort::BAUD_115200
93
+ @interface.data_bits = CommPort::DATA_BITS_8
94
+ @interface.parity = CommPort::PAR_NONE
95
+ @interface.stop_bits = CommPort::STOP_BITS_1
96
+ @interface.flow_control = CommPort::FLOW_OFF
97
+
98
+ @open = open?
99
+ end
100
+
101
+ # == Write function implementation
102
+ #
103
+ # @param [String] bytes
104
+ # @return [Int]
105
+ #
106
+ def write(bytes)
107
+ @interface.write(bytes)
108
+ end
109
+
110
+ # == Closing interface and freeing structures
111
+ #
112
+ # @return [Bool]
113
+ #
114
+ def close
115
+ @interface.close
116
+ @open = open?
117
+ !open?
118
+ end
119
+
120
+ # == Flashing buffer function
121
+ #
122
+ def flush
123
+ @interface.flush
124
+ end
125
+
126
+ # @return [Bool]
127
+ #
128
+ def open?
129
+ @interface && !@interface.closed?
130
+ end
131
+
132
+ # == read() implementation example
133
+ #
134
+ # @param +count+ [Int]
135
+ # @param +blocking+ [Bool]
136
+ #
137
+ # @return [String]
138
+ #
139
+ # === Alternative implementation:
140
+ # @usage:
141
+ #
142
+ # +timeout+ = blocking_value ? 15000 : 0
143
+ # +@interface.timeout+ = +timeout+
144
+ # +@interface.read( +count+ )+
145
+ #
146
+ def read(count, blocking = false)
147
+ array = []
148
+
149
+ bytes_count = (count == -1) ? @interface.available? : count
150
+
151
+ if blocking
152
+ bytes = read_io_until(count, count)
153
+ array.push bytes if bytes
154
+ else
155
+ bytes_count.times do
156
+ byte = @interface.read(1)
157
+ array.push byte if byte
158
+ end
159
+ end
160
+ array.empty? ? nil : array.join
161
+ end
162
+
163
+ private
164
+
165
+ # == simulate blocking function
166
+ #
167
+ # @param +count+ [Int]
168
+ # @param +up_to+ [Int]
169
+ #
170
+ # no direct ruby usage
171
+ #
172
+ def block_io_until(count, up_to)
173
+ while @interface.available? < count && up_to > 0
174
+ up_to -= 1
175
+ end
176
+ up_to > 0
177
+ end
178
+
179
+ # == simulate blocking function
180
+ #
181
+ # @param +count+ [Int]
182
+ # @param +up_to+ [Int]
183
+ #
184
+ # no direct ruby usage
185
+ #
186
+ def read_io_until(count, up_to)
187
+ until block_io_until(count, up_to)
188
+ sleep 0.001
189
+ end
190
+ read(count)
191
+ end
192
+
193
+ end
194
+
195
+ ###### Then =>
196
+
197
+ adapter = MyAdapter.new("/dev/ttyACM0")
198
+
199
+ adapter.open? #=> true
200
+
201
+ adapter.write 'Hello, world!" #=> 13
62
202
 
203
+ ```
63
204
 
64
- ## Contributing
205
+ ## Contributing
@@ -0,0 +1,5 @@
1
+ <atlassian-ide-plugin>
2
+ <project-configuration id="1">
3
+ <servers id="2" />
4
+ </project-configuration>
5
+ </atlassian-ide-plugin>
data/cucumber.yml CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
4
4
  rerun_opts = rerun.to_s.strip.empty? ? "--format progress features" : "--format pretty #{rerun}"
5
- std_opts = "--format pretty features --tags ~@wip --tag ~@wip-new-core -r features --strict"
5
+ std_opts = "--format pretty features --tags ~@wip -r features --strict"
6
6
 
7
7
 
8
8
  wip_opts = "--color -r features --tags @wip:3,@wip-new-core"
@@ -14,8 +14,8 @@ legacy_opts << " --tags ~@wip-jruby" if defined?(JRUBY_VERSION)
14
14
 
15
15
  %>
16
16
 
17
- default: <%= std_opts %> --tags ~@jruby features/.cucumber
18
- windows_mri: <%= std_opts %> --tags ~@jruby --tags ~@spork --tags ~@wire --tags ~@needs-many-fonts CUCUMBER_FORWARD_SLASH_PATHS=true
17
+ default: <%= std_opts %> --tags ~@jruby features
18
+ windows_mri: <%= std_opts %> --tags ~@jruby
19
19
 
20
20
  ruby_1_9: <%= std_opts %> --tags ~@jruby
21
21
  ruby_2_0: <%= std_opts %> --tags ~@jruby
@@ -18,7 +18,7 @@
18
18
  #include <ruby.h>
19
19
 
20
20
 
21
- #define VERSION "3.0.0-rc"
21
+ #define VERSION "2.0.7"
22
22
 
23
23
 
24
24
  #define LS_CTS 0x01
@@ -2,8 +2,8 @@ require 'mkmf'
2
2
  require 'rbconfig'
3
3
 
4
4
  if ENV['DEBUG_C']
5
- $CFLAGS << " -DDEBUG"
6
- $CFLAGS << " -g -O"
5
+ $CFLAGS << ' -DDEBUG'
6
+ $CFLAGS << ' -g -O'
7
7
  $stdout.puts "compiling in debug mode... flags: #{$CFLAGS}"
8
8
  end
9
9
 
@@ -11,82 +11,49 @@ def root(path)
11
11
  File.expand_path("../#{path}/", __FILE__)
12
12
  end
13
13
 
14
- dir_config("rs_232")
14
+ dir_config('rs_232')
15
15
 
16
16
  $warnflags = '-Wall'
17
17
 
18
- CPU = case RbConfig::CONFIG['host_cpu'].downcase
19
- when /i[3456]86/
20
- if RbConfig::CONFIG['host_os'] =~ /darwin/ && 0xfee1deadbeef.is_a?(Fixnum)
21
- "x86_64"
22
- else
23
- "i386"
24
- end
25
-
26
- when /amd64|x86_64/
27
- "x86_64"
28
-
29
- when /ppc64|powerpc64/
30
- "powerpc64"
31
-
32
- when /ppc|powerpc/
33
- "powerpc"
34
-
35
- when /^arm/
36
- "arm"
37
-
38
- else
39
- RbConfig::CONFIG['host_cpu']
40
- end
41
-
42
- $stdout.puts "Detecting CPU... "
43
- $stdout.puts "CPU: #{CPU}"
44
-
45
18
  OS = case RbConfig::CONFIG['host_os'].downcase
46
19
  when /linux/
47
- "linux"
20
+ 'linux'
48
21
  when /darwin/
49
- "darwin"
22
+ 'darwin'
50
23
  when /freebsd/
51
- "freebsd"
24
+ 'freebsd'
52
25
  when /openbsd/
53
- "openbsd"
26
+ 'openbsd'
54
27
  when /sunos|solaris/
55
- "solaris"
28
+ 'solaris'
56
29
  when /mswin|mingw/
57
- "windows"
30
+ 'windows'
58
31
  else
59
32
  RbConfig::CONFIG['host_os'].downcase
60
33
  end
61
34
 
62
- $stdout.puts "Detecting OS... "
63
- $stdout.puts "OS: #{OS}"
64
- $stdout.puts
65
-
66
-
67
- have_header("ruby.h")
68
- have_header("port.h")
69
- have_header("stdio.h")
70
-
71
- if OS == "windows"
72
- $VPATH << "$(srcdir)/windows"
73
- $INCFLAGS += " -I$(srcdir)/windows"
74
- have_header("windows.h")
75
- have_header("fcntl.h")
76
- have_header("io.h")
77
- have_header("ruby/io.h")
78
- have_header("rubyio.h")
35
+ have_header('ruby.h')
36
+ have_header('stdio.h')
37
+
38
+ if OS == 'windows'
39
+ $VPATH << '$(srcdir)/windows'
40
+ $INCFLAGS += ' -I$(srcdir)/windows'
41
+ have_header('windows.h')
42
+ have_header('fcntl.h')
43
+ have_header('io.h')
44
+ have_header('ruby/io.h')
45
+ have_header('rubyio.h')
79
46
  elsif %w(linux darwin).include? OS
80
- $VPATH << " $(srcdir)/posix"
81
- $INCFLAGS += " -I$(srcdir)/posix"
82
- have_header("termios.h")
83
- have_header("unistd.h")
84
- have_header("string.h")
85
- have_header("fcntl.h")
86
- have_header("errno.h")
87
- have_header("sys/ioctl.h")
47
+ $VPATH << ' $(srcdir)/posix'
48
+ $INCFLAGS += ' -I$(srcdir)/posix'
49
+ have_header('termios.h')
50
+ have_header('unistd.h')
51
+ have_header('string.h')
52
+ have_header('fcntl.h')
53
+ have_header('errno.h')
54
+ have_header('sys/ioctl.h')
88
55
  else
89
- raise "RS-233 implementation is not tested for this #{OS} palform."
56
+ raise "RS-233 implementation is not tested for this #{OS} platform."
90
57
  end
91
58
 
92
59
  $objs = %w(constants.o port.o initializer.o)
@@ -1,8 +1,10 @@
1
1
  Feature: Connection
2
2
 
3
- Scenario: Should have an ability to check open or not
3
+ As an QA
4
+ in order to test connection object I will create new one and ensure that it is opened
4
5
 
6
+ Scenario: Should have an ability to check open or not
5
7
 
6
- * connection instance "should" be available
7
- * I "close" connection
8
- * connection instance "should not" be available
8
+ Given connection instance "should" be available
9
+ Then I "close" connection
10
+ And connection instance "should not" be available
@@ -1,5 +1,4 @@
1
1
  After do
2
- adapter.close
3
- logger.debug "Closed..."
2
+ adapter.close if adapter.open?
4
3
  end
5
4
 
@@ -1,7 +1,6 @@
1
1
  require 'cucumber'
2
- require 'cucumber/formatter/unicode'
3
- require File.expand_path("../../../lib/rs_232", __FILE__)
4
- require File.expand_path("../adapter", __FILE__)
2
+ require 'rs_232'
3
+ require_relative '../../spec/support/adapter'
5
4
 
6
5
  # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
7
6
  #
@@ -11,33 +10,6 @@ def expand_path(path)
11
10
  File.expand_path(path, File.dirname(__FILE__))
12
11
  end
13
12
 
14
-
15
- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
16
- #
17
- # ENV
18
- #
19
- config = expand_path '../config/config.yml'
20
- if File.file? config
21
- require 'yaml'
22
- env = YAML.load File.read config
23
- env.each do |key, value|
24
- if ENV['DEBUG'] or env['DEBUG']
25
- if ENV[key]
26
- puts "Set `#{key}` to `#{ENV[key]}`."
27
- else
28
- puts "Set `#{key}` to default `#{value}`."
29
- end
30
- end
31
-
32
- ENV[key] ||= value.to_s if value
33
- end
34
- else
35
- if ENV['DEBUG']
36
- puts "Please check `features/support/config` folder for existing file `config.yml`"
37
- puts
38
- end
39
- end
40
-
41
13
  # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
42
14
  #
43
15
  # Load only if bundled console
@@ -63,7 +35,7 @@ class LogFormatter < ::Logger::Formatter
63
35
  private
64
36
 
65
37
  def format_datetime(time)
66
- time.strftime("%Y-%m-%d %H:%M:%S.") << "%06d " % time.usec
38
+ time.strftime('%Y-%m-%d %H:%M:%S.') << "%06d " % time.usec
67
39
  end
68
40
 
69
41
  end
@@ -80,21 +52,17 @@ end
80
52
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
81
53
 
82
54
  def serial_port
83
- if ENV["SERIAL_PORT"].nil?
84
- $stdout.write "Enter serial port name: "
85
- ENV["SERIAL_PORT"] = $stdin.gets.chomp
55
+ if ENV['SERIAL_PORT'].nil?
56
+ $stdout.write 'Enter serial port details: '
57
+ ENV['SERIAL_PORT'] = $stdin.gets.chomp
86
58
  end
87
- ENV["SERIAL_PORT"]
59
+ ENV['SERIAL_PORT']
88
60
  end
89
61
 
90
62
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
91
63
 
92
64
  def adapter
93
- @adapter ||= Adapter::Dev.new(serial_port)
94
- end
95
-
96
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
97
-
98
- def transmit(string)
99
- adpter.tx(string)
100
- end
65
+ @adapter ||= Adapter::Dev.new(serial_port) do |message|
66
+ logger.debug message
67
+ end
68
+ end
@@ -1,7 +1,7 @@
1
1
  task :ruby_env do
2
2
  RUBY_APP = if RUBY_PLATFORM =~ /java/
3
- "jruby"
4
- else
5
- "ruby"
6
- end unless defined? RUBY_APP
3
+ 'jruby'
4
+ else
5
+ 'ruby'
6
+ end unless defined? RUBY_APP
7
7
  end
data/gem_tasks/rspec.rake CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'rspec/core/rake_task'
2
2
 
3
- desc "Run RSpec"
3
+ desc 'Run RSpec'
4
4
  RSpec::Core::RakeTask.new do |t|
5
5
  t.verbose = true
6
6
  end
@@ -1,6 +1,6 @@
1
1
  module Rs232
2
2
  module Version
3
- MAJOR, MINOR, PATCH = 2, 0, 5
3
+ MAJOR, MINOR, PATCH = 2, 0, 7
4
4
  STRING = [MAJOR, MINOR, PATCH].join('.')
5
5
  end
6
6