wj-em-rubyserial 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c868982a739ea09b1021f117cc94e501f9dd9b43
4
+ data.tar.gz: 37868149710dba49c1ee5ef29b3c015ab9cfe12b
5
+ SHA512:
6
+ metadata.gz: 2f7b76d675ae98033b5b168ebd87d74d4e6c9697a46a8b80c59aa928df2c6f42cc7822d2d86359610e0249e7b69ec3476876721475183809754e552f4ea69fd6
7
+ data.tar.gz: ec682073cb2bc5c55f9072df078408bbfeed5408c11bec9cdf22043acc92861a74af270a338a5655538c53c37d659c1d7e77496b403f1ce7d78d6b7a5cc7ea3b
@@ -0,0 +1,25 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .rvmrc
24
+ *.swp
25
+ socat.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
6
+ - 2.1.1
7
+ - jruby-18mode
8
+ - jruby-19mode
9
+ - jruby-head
10
+ - ree
11
+ install:
12
+ - sudo apt-get update && sudo apt-get install --force-yes socat
13
+ script:
14
+ - bundle install
15
+ - bundle exec rspec
@@ -0,0 +1,11 @@
1
+ ## 0.0.2 (2015-09-17)
2
+
3
+ Bugfixes:
4
+
5
+ - Fix "Errno::EBADF - Bad file descriptor" error under jruby that would occur after some time of working
6
+
7
+ ## 0.0.3(2020-09-01)
8
+
9
+ Bugfixes:
10
+
11
+ - Fix "Cannot delete while iterating rbtree" error, by removing the require 'em/pure_ruby' and replacing it with require 'eventmachine'
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in em-rubyserial.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Jesse
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,38 @@
1
+ # Em::Rubyserial
2
+
3
+ EventMachine serial port functionality that should work on all* ruby flavors (including MRI, jruby; and various operating systems including linux, windows, and apple)
4
+
5
+ The original gem fails on virtually all versions of EventMachine, due to a weird rbtree errors. I fixed this, by fixing what looks like an erroneous require statement.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'em-rubyserial'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install em-rubyserial
20
+
21
+ ## Usage
22
+
23
+ EM.run do
24
+ serial = EventMachine.open_serial('/dev/ttyS2', 9600, 8)
25
+ serial.send_data "foo"
26
+
27
+ serial.on_data do |data|
28
+ puts data
29
+ end
30
+ end
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it ( https://github.com/wordjelly/em-rubyserial/fork )
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create a new Pull Request
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require "rspec/core/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new
6
+
7
+ task :default => :spec
8
+ task :test => :spec
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'em-rubyserial/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "wj-em-rubyserial"
8
+ spec.version = Em::Rubyserial::VERSION
9
+ spec.authors = ["Bhargav Raut"]
10
+ spec.email = ["bhargav.r.raut@gmail.com"]
11
+ spec.summary = %q{EventMachine serial port}
12
+ spec.description = %q{Refactored to play nice with eventmachine}
13
+ spec.homepage = "https://github.com/wordjelly/em-rubyserial"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "rubyserial"
22
+ spec.add_runtime_dependency "eventmachine"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.6"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec", "~> 3"
27
+ end
@@ -0,0 +1,81 @@
1
+ require "em-rubyserial/version"
2
+ require 'eventmachine'
3
+ require 'rubyserial'
4
+
5
+ module EventMachine
6
+ class Connection
7
+ def on_data(&blk)
8
+ @on_data = blk
9
+ end
10
+
11
+ def trigger_on_data(data)
12
+ @on_data.call(data) if @on_data
13
+ end
14
+
15
+ def receive_data data
16
+ trigger_on_data(data)
17
+ end
18
+
19
+ def associate_callback_target(sig)
20
+ return(nil)
21
+ end
22
+ end
23
+ end
24
+
25
+ module EventMachine
26
+ class << self
27
+ def connect_serial(dev, baud, databits)
28
+ SerialPort.open(dev, baud, databits).uuid
29
+ end
30
+
31
+ def open_serial(dev, baud, databits, handler=nil)
32
+ klass = if(handler and handler.is_a?(Class))
33
+ handler
34
+ else
35
+ Class.new(Connection) {handler and include handler}
36
+ end
37
+ uuid = connect_serial(dev, baud, databits)
38
+ connection = klass.new uuid
39
+ @conns[uuid] = connection
40
+ block_given? and yield connection
41
+ connection
42
+ end
43
+ end
44
+
45
+ class SerialPort < StreamObject
46
+ def self.open(dev, baud, databits)
47
+ serialport = ::Serial.new(dev, baud, databits)
48
+ if RUBY_PLATFORM == "java"
49
+ io = FFI::FileDescriptorIO.new(serialport.instance_variable_get(:@fd).to_i)
50
+ else
51
+ io = IO.new(serialport.instance_variable_get(:@fd), 'r+')
52
+ end
53
+ self.new(io)
54
+ end
55
+
56
+ def initialize(io)
57
+ super
58
+ end
59
+
60
+ def eventable_read
61
+ @last_activity = Reactor.instance.current_loop_time
62
+ begin
63
+ if io.respond_to?(:read_nonblock)
64
+ 10.times {
65
+ data = io.read_nonblock(4096)
66
+ EventMachine::event_callback uuid, ConnectionData, data
67
+ }
68
+ else
69
+ data = io.sysread(4096)
70
+ EventMachine::event_callback uuid, ConnectionData, data
71
+ end
72
+ rescue Errno::EAGAIN, Errno::EWOULDBLOCK, EOFError
73
+ # no-op
74
+ rescue Errno::ECONNRESET, Errno::ECONNREFUSED
75
+ @close_scheduled = true
76
+ EventMachine::event_callback uuid, ConnectionUnbound, nil
77
+ end
78
+ end
79
+
80
+ end
81
+ end
@@ -0,0 +1,5 @@
1
+ module Em
2
+ module Rubyserial
3
+ VERSION = "0.0.4"
4
+ end
5
+ end
@@ -0,0 +1,40 @@
1
+ describe "basic reading and writing" do
2
+ before do
3
+ File.delete('socat.log') if File.file?('socat.log')
4
+
5
+ Thread.new do
6
+ system('socat -lf socat.log -d -d pty,raw,echo=0 pty,raw,echo=0')
7
+ end
8
+
9
+ @ptys = nil
10
+
11
+ loop do
12
+ if File.file? 'socat.log'
13
+ @file = File.open('socat.log', "r")
14
+ @fileread = @file.read
15
+ unless @fileread.count("\n") < 3
16
+ @ptys = @fileread.scan(/PTY is (.*)/)
17
+ break
18
+ end
19
+ end
20
+ end
21
+
22
+ require 'rubyserial'
23
+ @sp2 = Serial.new(@ptys[1][0])
24
+ @sp2.write('hello')
25
+
26
+ # small delay so it can write to the other port.
27
+ sleep 5
28
+ end
29
+
30
+ it "should read and write" do
31
+ EM.run do
32
+ serial = EventMachine.open_serial(@ptys[0][0], 9600, 8)
33
+
34
+ serial.on_data do |data|
35
+ expect(data).to eq "hello"
36
+ EM.stop_event_loop
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,93 @@
1
+ require 'bundler/setup'
2
+
3
+ require 'em-rubyserial'
4
+
5
+ # This file was generated by the `rspec --init` command. Conventionally, all
6
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
7
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
8
+ # file to always be loaded, without a need to explicitly require it in any files.
9
+ #
10
+ # Given that it is always loaded, you are encouraged to keep this file as
11
+ # light-weight as possible. Requiring heavyweight dependencies from this file
12
+ # will add to the boot time of your test suite on EVERY test run, even for an
13
+ # individual file that may not need all of that loaded. Instead, consider making
14
+ # a separate helper file that requires the additional dependencies and performs
15
+ # the additional setup, and require it from the spec files that actually need it.
16
+ #
17
+ # The `.rspec` file also contains a few flags that are not defaults but that
18
+ # users commonly want.
19
+ #
20
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
21
+ RSpec.configure do |config|
22
+ # rspec-expectations config goes here. You can use an alternate
23
+ # assertion/expectation library such as wrong or the stdlib/minitest
24
+ # assertions if you prefer.
25
+ config.expect_with :rspec do |expectations|
26
+ # This option will default to `true` in RSpec 4. It makes the `description`
27
+ # and `failure_message` of custom matchers include text for helper methods
28
+ # defined using `chain`, e.g.:
29
+ # be_bigger_than(2).and_smaller_than(4).description
30
+ # # => "be bigger than 2 and smaller than 4"
31
+ # ...rather than:
32
+ # # => "be bigger than 2"
33
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
34
+ end
35
+
36
+ # rspec-mocks config goes here. You can use an alternate test double
37
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
38
+ config.mock_with :rspec do |mocks|
39
+ # Prevents you from mocking or stubbing a method that does not exist on
40
+ # a real object. This is generally recommended, and will default to
41
+ # `true` in RSpec 4.
42
+ mocks.verify_partial_doubles = true
43
+ end
44
+
45
+ # The settings below are suggested to provide a good initial experience
46
+ # with RSpec, but feel free to customize to your heart's content.
47
+ =begin
48
+ # These two settings work together to allow you to limit a spec run
49
+ # to individual examples or groups you care about by tagging them with
50
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
51
+ # get run.
52
+ config.filter_run :focus
53
+ config.run_all_when_everything_filtered = true
54
+
55
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
56
+ # For more details, see:
57
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
58
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
59
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
60
+ config.disable_monkey_patching!
61
+
62
+ # This setting enables warnings. It's recommended, but in some cases may
63
+ # be too noisy due to issues in dependencies.
64
+ config.warnings = true
65
+
66
+ # Many RSpec users commonly either run the entire suite or an individual
67
+ # file, and it's useful to allow more verbose output when running an
68
+ # individual spec file.
69
+ if config.files_to_run.one?
70
+ # Use the documentation formatter for detailed output,
71
+ # unless a formatter has already been configured
72
+ # (e.g. via a command-line flag).
73
+ config.default_formatter = 'doc'
74
+ end
75
+
76
+ # Print the 10 slowest examples and example groups at the
77
+ # end of the spec run, to help surface which specs are running
78
+ # particularly slow.
79
+ config.profile_examples = 10
80
+
81
+ # Run specs in random order to surface order dependencies. If you find an
82
+ # order dependency and want to debug it, you can fix the order by providing
83
+ # the seed, which is printed after each run.
84
+ # --seed 1234
85
+ config.order = :random
86
+
87
+ # Seed global randomization in this process using the `--seed` CLI option.
88
+ # Setting this allows you to use `--seed` to deterministically reproduce
89
+ # test failures related to randomization by passing the same `--seed` value
90
+ # as the one that triggered the failure.
91
+ Kernel.srand config.seed
92
+ =end
93
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wj-em-rubyserial
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Bhargav Raut
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-09-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubyserial
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: eventmachine
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3'
83
+ description: Refactored to play nice with eventmachine
84
+ email:
85
+ - bhargav.r.raut@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - CHANGELOG.md
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - em-rubyserial.gemspec
99
+ - lib/em-rubyserial.rb
100
+ - lib/em-rubyserial/version.rb
101
+ - spec/basic_rw_spec.rb
102
+ - spec/spec_helper.rb
103
+ homepage: https://github.com/wordjelly/em-rubyserial
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.6.14.4
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: EventMachine serial port
127
+ test_files:
128
+ - spec/basic_rw_spec.rb
129
+ - spec/spec_helper.rb