em-rubyserial 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b9ff7490d9899a710525d8f06be80350b3ddde3c
4
+ data.tar.gz: 6c811ac5335b4540df4b131249239ca52a3eaa17
5
+ SHA512:
6
+ metadata.gz: 8e5c06b96a41c1b67677f451a162f23b69b186c72ba185c8d49a813347b5a166bdd2f81e3902e8ba14977fe47c38db2c16980c6208f02c62efbc1679e753ce5f
7
+ data.tar.gz: c254e875c319f3a72e705b46438ac60b5a467092fc2fe3249b9e22b8649522a8c8a6676161ad1f44036642e6d8c5596818b1397d04bee681a550174a344da909
data/.gitignore ADDED
@@ -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
data/.travis.yml ADDED
@@ -0,0 +1,16 @@
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
+ - rbx-2
10
+ - jruby-head
11
+ - ree
12
+ install:
13
+ - sudo apt-get update && sudo apt-get install --force-yes socat
14
+ script:
15
+ - bundle install
16
+ - bundle exec rspec
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
data/LICENSE.txt ADDED
@@ -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.
data/README.md ADDED
@@ -0,0 +1,50 @@
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
+ (* for some values of all)
6
+
7
+ [![Build Status](https://travis-ci.org/jcantara/em-rubyserial.svg?branch=master)](https://travis-ci.org/jcantara/em-rubyserial)
8
+
9
+ Uses the following gem for serial port connectivity:
10
+ https://github.com/hybridgroup/rubyserial
11
+
12
+ Essentially copies this gem:
13
+ https://github.com/railsbob/em-serialport
14
+
15
+ but replaces the serialport gem with the rubyserial gem, and does some file descriptor handling.
16
+
17
+ There is currently as of this writing no license on the em-serialport gem, so hopefully this amount of attribution is satisfactory.
18
+
19
+ ## Installation
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ gem 'em-rubyserial'
24
+
25
+ And then execute:
26
+
27
+ $ bundle
28
+
29
+ Or install it yourself as:
30
+
31
+ $ gem install em-rubyserial
32
+
33
+ ## Usage
34
+
35
+ EM.run do
36
+ serial = EventMachine.open_serial('/dev/ttyS2', 9600, 8)
37
+ serial.send_data "foo"
38
+
39
+ serial.on_data do |data|
40
+ puts data
41
+ end
42
+ end
43
+
44
+ ## Contributing
45
+
46
+ 1. Fork it ( https://github.com/jcantara/em-rubyserial/fork )
47
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
48
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
49
+ 4. Push to the branch (`git push origin my-new-feature`)
50
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -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 = "em-rubyserial"
8
+ spec.version = Em::Rubyserial::VERSION
9
+ spec.authors = ["Jesse Cantara"]
10
+ spec.email = ["jcantara@gmail.com"]
11
+ spec.summary = %q{EventMachine serial port}
12
+ spec.description = %q{EventMachine functionality for rubyserial gem that functions under a wide assortment of rubies}
13
+ spec.homepage = "https://github.com/jcantara/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,5 @@
1
+ module Em
2
+ module Rubyserial
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,83 @@
1
+ require "em-rubyserial/version"
2
+
3
+ require 'em/pure_ruby'
4
+ require 'rubyserial'
5
+
6
+ module EventMachine
7
+ class Connection
8
+ def on_data(&blk)
9
+ @on_data = blk
10
+ end
11
+
12
+ def trigger_on_data(data)
13
+ @on_data.call(data) if @on_data
14
+ end
15
+
16
+ def receive_data data
17
+ trigger_on_data(data)
18
+ end
19
+
20
+ def associate_callback_target(sig)
21
+ return(nil)
22
+ end
23
+ end
24
+ end
25
+
26
+ module EventMachine
27
+ class << self
28
+ def connect_serial(dev, baud, databits)
29
+ SerialPort.open(dev, baud, databits).uuid
30
+ end
31
+
32
+ def open_serial(dev, baud, databits, handler=nil)
33
+ klass = if(handler and handler.is_a?(Class))
34
+ handler
35
+ else
36
+ Class.new(Connection) {handler and include handler}
37
+ end
38
+ uuid = connect_serial(dev, baud, databits)
39
+ connection = klass.new uuid
40
+ @conns[uuid] = connection
41
+ block_given? and yield connection
42
+ connection
43
+ end
44
+ end
45
+
46
+ class SerialPort < StreamObject
47
+ def self.open(dev, baud, databits)
48
+ serialport = ::Serial.new(dev, baud, databits)
49
+ if RUBY_PLATFORM == "java"
50
+ io = IO.new(FFI::IO.for_fd(serialport.instance_variable_get(:@fd)).to_i, 'r+')
51
+ else
52
+ io = IO.new(serialport.instance_variable_get(:@fd), 'r+')
53
+ end
54
+ io.instance_variable_set(:@serialport, serialport) # hang on to our serial port so it doesn't get closed and close our file descriptor
55
+ self.new(io)
56
+ end
57
+
58
+ def initialize(io)
59
+ super
60
+ end
61
+
62
+ def eventable_read
63
+ @last_activity = Reactor.instance.current_loop_time
64
+ begin
65
+ if io.respond_to?(:read_nonblock)
66
+ 10.times {
67
+ data = io.read_nonblock(4096)
68
+ EventMachine::event_callback uuid, ConnectionData, data
69
+ }
70
+ else
71
+ data = io.sysread(4096)
72
+ EventMachine::event_callback uuid, ConnectionData, data
73
+ end
74
+ rescue Errno::EAGAIN, Errno::EWOULDBLOCK, EOFError
75
+ # no-op
76
+ rescue Errno::ECONNRESET, Errno::ECONNREFUSED
77
+ @close_scheduled = true
78
+ EventMachine::event_callback uuid, ConnectionUnbound, nil
79
+ end
80
+ end
81
+
82
+ end
83
+ 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\x00"
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,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: em-rubyserial
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jesse Cantara
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubyserial
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - '>='
23
+ - !ruby/object:Gem::Version
24
+ version: '0'
25
+ prerelease: false
26
+ type: :runtime
27
+ - !ruby/object:Gem::Dependency
28
+ name: eventmachine
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ prerelease: false
40
+ type: :runtime
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ~>
51
+ - !ruby/object:Gem::Version
52
+ version: '1.6'
53
+ prerelease: false
54
+ type: :development
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ prerelease: false
68
+ type: :development
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '3'
76
+ requirement: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ~>
79
+ - !ruby/object:Gem::Version
80
+ version: '3'
81
+ prerelease: false
82
+ type: :development
83
+ description: EventMachine functionality for rubyserial gem that functions under a wide assortment of rubies
84
+ email:
85
+ - jcantara@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .rspec
92
+ - .travis.yml
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - em-rubyserial.gemspec
98
+ - lib/em-rubyserial.rb
99
+ - lib/em-rubyserial/version.rb
100
+ - spec/basic_rw_spec.rb
101
+ - spec/spec_helper.rb
102
+ homepage: https://github.com/jcantara/em-rubyserial
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.1.9
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: EventMachine serial port
126
+ test_files:
127
+ - spec/basic_rw_spec.rb
128
+ - spec/spec_helper.rb