rs_232 2.0.7 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock DELETED
@@ -1,57 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- rs_232 (2.0.6)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- builder (3.2.2)
10
- coderay (1.1.0)
11
- cucumber (1.3.11)
12
- builder (>= 2.1.2)
13
- diff-lcs (>= 1.1.3)
14
- gherkin (~> 2.12)
15
- multi_json (>= 1.7.5, < 2.0)
16
- multi_test (>= 0.0.2)
17
- diff-lcs (1.2.5)
18
- docile (1.1.3)
19
- gherkin (2.12.2)
20
- multi_json (~> 1.3)
21
- method_source (0.8.2)
22
- multi_json (1.9.0)
23
- multi_test (0.0.3)
24
- pry (0.9.12.6)
25
- coderay (~> 1.0)
26
- method_source (~> 0.8)
27
- slop (~> 3.4)
28
- rake (10.1.1)
29
- rake-compiler (0.9.2)
30
- rake
31
- rspec (2.14.1)
32
- rspec-core (~> 2.14.0)
33
- rspec-expectations (~> 2.14.0)
34
- rspec-mocks (~> 2.14.0)
35
- rspec-core (2.14.8)
36
- rspec-expectations (2.14.5)
37
- diff-lcs (>= 1.1.3, < 2.0)
38
- rspec-mocks (2.14.6)
39
- simplecov (0.8.2)
40
- docile (~> 1.1.0)
41
- multi_json
42
- simplecov-html (~> 0.8.0)
43
- simplecov-html (0.8.0)
44
- slop (3.4.7)
45
-
46
- PLATFORMS
47
- ruby
48
-
49
- DEPENDENCIES
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
- rs_232!
56
- rspec (~> 2.14, >= 2.14.1)
57
- simplecov (~> 0.8, >= 0.8.2)
data/README.md DELETED
@@ -1,205 +0,0 @@
1
- # Rs232
2
-
3
- This is a rs-232 implementation as a Ruby extension in C.
4
-
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- gem 'rs_232'
10
-
11
- And then execute:
12
-
13
- $ bundle
14
-
15
- Or install it yourself as:
16
-
17
- $ gem install rs_232
18
-
19
- ## Usage
20
-
21
- ```ruby
22
-
23
- require "rs_232"
24
-
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
202
-
203
- ```
204
-
205
- ## Contributing
@@ -1,5 +0,0 @@
1
- <atlassian-ide-plugin>
2
- <project-configuration id="1">
3
- <servers id="2" />
4
- </project-configuration>
5
- </atlassian-ide-plugin>
data/cucumber.yml DELETED
@@ -1,24 +0,0 @@
1
- <%
2
-
3
- rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
4
- rerun_opts = rerun.to_s.strip.empty? ? "--format progress features" : "--format pretty #{rerun}"
5
- std_opts = "--format pretty features --tags ~@wip -r features --strict"
6
-
7
-
8
- wip_opts = "--color -r features --tags @wip:3,@wip-new-core"
9
- wip_opts << ",@wip-jruby:3" if defined?(JRUBY_VERSION)
10
-
11
- legacy_opts = ''
12
- legacy_opts << " --tags ~@wire" if defined?(JRUBY_VERSION)
13
- legacy_opts << " --tags ~@wip-jruby" if defined?(JRUBY_VERSION)
14
-
15
- %>
16
-
17
- default: <%= std_opts %> --tags ~@jruby features
18
- windows_mri: <%= std_opts %> --tags ~@jruby
19
-
20
- ruby_1_9: <%= std_opts %> --tags ~@jruby
21
- ruby_2_0: <%= std_opts %> --tags ~@jruby
22
- wip: --wip <%= wip_opts %> features
23
- none: --format pretty
24
- rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip --tag ~@wip-new-core
@@ -1,2 +0,0 @@
1
- SERIAL_PORT: COM20
2
- DEBUG: 0
@@ -1,10 +0,0 @@
1
- Feature: Connection
2
-
3
- As an QA
4
- in order to test connection object I will create new one and ensure that it is opened
5
-
6
- Scenario: Should have an ability to check open or not
7
-
8
- Given connection instance "should" be available
9
- Then I "close" connection
10
- And connection instance "should not" be available
@@ -1,33 +0,0 @@
1
- When /^connection instance "(should|should not)" be available$/ do |matcher|
2
-
3
- action = matcher == 'should' ? :should : :should_not
4
-
5
- if respond_to? :should
6
- adapter.open?.send(action, be_true)
7
- else
8
- assert_equal(adapter.open?, action == :should)
9
- end
10
-
11
- end
12
-
13
- Given /^I "(open|close)" connection$/ do |action|
14
-
15
- adapter.send(action)
16
-
17
- if action == 'close'
18
- if respond_to? :should
19
- adapter.open?.should be_false
20
- else
21
- assert_equal(connection.open?, false)
22
- end
23
- else
24
- if respond_to? :should
25
- adapter.open?.should be_true
26
- else
27
- assert_equal(connection.open?, true)
28
- end
29
- end
30
-
31
- end
32
-
33
-
@@ -1,4 +0,0 @@
1
- After do
2
- adapter.close if adapter.open?
3
- end
4
-
@@ -1,68 +0,0 @@
1
- require 'cucumber'
2
- require 'rs_232'
3
- require_relative '../../spec/support/adapter'
4
-
5
- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
6
- #
7
- # relative path location method
8
- #
9
- def expand_path(path)
10
- File.expand_path(path, File.dirname(__FILE__))
11
- end
12
-
13
- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
14
- #
15
- # Load only if bundled console
16
- #
17
-
18
- unless $0 =~ /cucumber/i
19
- runtime = Cucumber::Runtime.new
20
- runtime.load_programming_language('rb')
21
- end
22
-
23
-
24
- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
25
- #
26
- # logger impl
27
- #
28
-
29
- class LogFormatter < ::Logger::Formatter
30
-
31
- def call(severity, time, progname, msg)
32
- "#{format_datetime(time)}[TID:#{$$}] [EXT::#{severity}]: #{msg}\n"
33
- end
34
-
35
- private
36
-
37
- def format_datetime(time)
38
- time.strftime('%Y-%m-%d %H:%M:%S.') << "%06d " % time.usec
39
- end
40
-
41
- end
42
-
43
- def logger
44
- @logger ||= begin
45
- l = ::Logger.new($stdout)
46
- l.level = Logger::DEBUG
47
- l.formatter = LogFormatter.new
48
- l
49
- end
50
- end
51
-
52
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
53
-
54
- def serial_port
55
- if ENV['SERIAL_PORT'].nil?
56
- $stdout.write 'Enter serial port details: '
57
- ENV['SERIAL_PORT'] = $stdin.gets.chomp
58
- end
59
- ENV['SERIAL_PORT']
60
- end
61
-
62
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
63
-
64
- def adapter
65
- @adapter ||= Adapter::Dev.new(serial_port) do |message|
66
- logger.debug message
67
- end
68
- end
data/gem_tasks/cov.rake DELETED
@@ -1,5 +0,0 @@
1
- desc 'Run all tests and collect code coverage'
2
- task :cov do
3
- ENV['SIMPLECOV'] = 'features'
4
- Rake::Task['default'].invoke
5
- end
@@ -1,23 +0,0 @@
1
- require 'cucumber/rake/task'
2
- require 'cucumber/platform'
3
-
4
- class Cucumber::Rake::Task
5
- def set_profile_for_current_ruby
6
- self.profile = if Cucumber::JRUBY
7
- Cucumber::WINDOWS ? 'jruby_win' : 'jruby'
8
- elsif Cucumber::WINDOWS_MRI
9
- 'windows_mri'
10
- elsif Cucumber::RUBY_1_9
11
- 'ruby_1_9'
12
- elsif Cucumber::RUBY_2_0
13
- 'ruby_2_0'
14
- end
15
- end
16
- end
17
-
18
- Cucumber::Rake::Task.new(:features) do |t|
19
- t.fork = true
20
- t.set_profile_for_current_ruby
21
- end
22
-
23
- task :cucumber => :features
data/gem_tasks/doc.rake DELETED
@@ -1,12 +0,0 @@
1
- require 'rdoc/task'
2
-
3
- desc "builds documentation for the 'rs_232' gem"
4
- Rake::RDocTask.new :doc do |rd|
5
-
6
- base = File.expand_path("../", File.dirname(__FILE__))
7
- base.sub!(/^#{Regexp::escape FileUtils.pwd}\/?/, './')
8
-
9
- rd.main = File.join(base, "README.md")
10
- rd.rdoc_files.include(File.join(base, "README.md"), File.join(base, "lib/**/*.rb"))
11
- rd.rdoc_dir = "./doc/rs_232"
12
- end
@@ -1,7 +0,0 @@
1
- task :ruby_env do
2
- RUBY_APP = if RUBY_PLATFORM =~ /java/
3
- 'jruby'
4
- else
5
- 'ruby'
6
- end unless defined? RUBY_APP
7
- end
data/gem_tasks/rspec.rake DELETED
@@ -1,6 +0,0 @@
1
- require 'rspec/core/rake_task'
2
-
3
- desc 'Run RSpec'
4
- RSpec::Core::RakeTask.new do |t|
5
- t.verbose = true
6
- end
data/rs_232.iml DELETED
@@ -1,30 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <module type="RUBY_MODULE" version="4">
3
- <component name="NewModuleRootManager" inherit-compiler-output="true">
4
- <exclude-output />
5
- <content url="file://$MODULE_DIR$" />
6
- <orderEntry type="jdk" jdkName="RVM: ruby-2.1.1" jdkType="RUBY_SDK" />
7
- <orderEntry type="sourceFolder" forTests="false" />
8
- <orderEntry type="library" scope="PROVIDED" name="builder (v3.2.2, RVM: ruby-2.1.1) [gem]" level="application" />
9
- <orderEntry type="library" scope="PROVIDED" name="bundler (v1.5.3, RVM: ruby-2.1.1) [gem]" level="application" />
10
- <orderEntry type="library" scope="PROVIDED" name="coderay (v1.1.0, RVM: ruby-2.1.1) [gem]" level="application" />
11
- <orderEntry type="library" scope="PROVIDED" name="cucumber (v1.3.11, RVM: ruby-2.1.1) [gem]" level="application" />
12
- <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.2.5, RVM: ruby-2.1.1) [gem]" level="application" />
13
- <orderEntry type="library" scope="PROVIDED" name="docile (v1.1.3, RVM: ruby-2.1.1) [gem]" level="application" />
14
- <orderEntry type="library" scope="PROVIDED" name="gherkin (v2.12.2, RVM: ruby-2.1.1) [gem]" level="application" />
15
- <orderEntry type="library" scope="PROVIDED" name="method_source (v0.8.2, RVM: ruby-2.1.1) [gem]" level="application" />
16
- <orderEntry type="library" scope="PROVIDED" name="multi_json (v1.9.0, RVM: ruby-2.1.1) [gem]" level="application" />
17
- <orderEntry type="library" scope="PROVIDED" name="multi_test (v0.0.3, RVM: ruby-2.1.1) [gem]" level="application" />
18
- <orderEntry type="library" scope="PROVIDED" name="pry (v0.9.12.6, RVM: ruby-2.1.1) [gem]" level="application" />
19
- <orderEntry type="library" scope="PROVIDED" name="rake (v10.1.1, RVM: ruby-2.1.1) [gem]" level="application" />
20
- <orderEntry type="library" scope="PROVIDED" name="rake-compiler (v0.9.2, RVM: ruby-2.1.1) [gem]" level="application" />
21
- <orderEntry type="library" scope="PROVIDED" name="rspec (v2.14.1, RVM: ruby-2.1.1) [gem]" level="application" />
22
- <orderEntry type="library" scope="PROVIDED" name="rspec-core (v2.14.8, RVM: ruby-2.1.1) [gem]" level="application" />
23
- <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v2.14.5, RVM: ruby-2.1.1) [gem]" level="application" />
24
- <orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v2.14.6, RVM: ruby-2.1.1) [gem]" level="application" />
25
- <orderEntry type="library" scope="PROVIDED" name="simplecov (v0.8.2, RVM: ruby-2.1.1) [gem]" level="application" />
26
- <orderEntry type="library" scope="PROVIDED" name="simplecov-html (v0.8.0, RVM: ruby-2.1.1) [gem]" level="application" />
27
- <orderEntry type="library" scope="PROVIDED" name="slop (v3.4.7, RVM: ruby-2.1.1) [gem]" level="application" />
28
- </component>
29
- </module>
30
-
@@ -1,15 +0,0 @@
1
- begin
2
- # Suppress warnings in order not to pollute stdout which tests expectations rely on
3
- $VERBOSE = nil if defined?(JRUBY_VERSION)
4
-
5
- require 'simplecov'
6
-
7
- SimpleCov.root(File.expand_path(File.dirname(__FILE__) + '/..'))
8
- SimpleCov.start do
9
- add_filter '/features/'
10
- add_filter '/spec/'
11
- end
12
-
13
- rescue LoadError
14
- warn("Unable to load simplecov gem")
15
- end
data/spec/spec_helper.rb DELETED
@@ -1,15 +0,0 @@
1
- require 'bundler'
2
- require 'bundler/setup'
3
- require 'rspec'
4
- require 'rs_232'
5
-
6
- Dir[File.expand_path('support/**/*.rb', File.dirname(__FILE__))].each do |f|
7
- require f if File.file?(f)
8
- end
9
-
10
- RSpec.configure do |config|
11
- config.color_enabled = true
12
- config.formatter = :documentation
13
- end
14
-
15
- load File.expand_path '../simplecov_setup.rb', __FILE__