em-serialport 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.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'rake'
7
+ end
8
+
9
+ group :test do
10
+ gem 'rspec', '2.8.0'
11
+ end
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler'
2
+ require 'rspec/core/rake_task'
3
+
4
+ Bundler::GemHelper.install_tasks
5
+ RSpec::Core::RakeTask.new('spec')
6
+ task :default => :spec
@@ -0,0 +1,23 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require "em-serialport/version"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "em-serialport"
6
+ s.version = Em::Serialport::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Anup Narkhede"]
9
+ s.email = ["anup@infinitypulse.com"]
10
+ s.homepage = "http://anup.info"
11
+ s.summary = %q{EventMachine compatible serialport library}
12
+ s.description = %q{}
13
+
14
+ s.rubyforge_project = "em-serialport"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency "eventmachine", "0.12.10"
22
+ s.add_dependency "serialport"
23
+ end
@@ -0,0 +1,17 @@
1
+ module EventMachine
2
+ class Connection
3
+ def on_data(&blk); @on_data = blk; end
4
+
5
+ def trigger_on_data(data)
6
+ @on_data.call(data) if @on_data
7
+ end
8
+
9
+ def receive_data data
10
+ trigger_on_data(data)
11
+ end
12
+
13
+ def associate_callback_target(sig)
14
+ return(nil)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,31 @@
1
+ module EventMachine
2
+ class << self
3
+ def connect_serial(dev, baud, databits, stopbits, parity)
4
+ SerialPort.open(dev, baud, databits, stopbits, parity).uuid
5
+ end
6
+ end
7
+
8
+ def EventMachine::open_serial(dev, baud, databits, stopbits, parity, handler=nil)
9
+ klass = if(handler and handler.is_a?(Class))
10
+ handler
11
+ else
12
+ Class.new(Connection) {handler and include handler}
13
+ end
14
+ uuid = connect_serial(dev, baud, databits, stopbits, parity)
15
+ connection = klass.new uuid
16
+ @conns[uuid] = connection
17
+ block_given? and yield connection
18
+ connection
19
+ end
20
+
21
+ class SerialPort < StreamObject
22
+ def self.open(dev, baud, databits, stopbits, parity)
23
+ io = ::SerialPort.new(dev, baud, databits, stopbits, parity)
24
+ self.new(io)
25
+ end
26
+
27
+ def initialize(io)
28
+ super
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,5 @@
1
+ module Em
2
+ module Serialport
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ $eventmachine_library = :pure_ruby
2
+ require 'eventmachine'
3
+ require 'serialport'
4
+
5
+ %w(serial_port connection).each do |file|
6
+ require "em-serialport/#{file}"
7
+ end
data/readme.md ADDED
@@ -0,0 +1,23 @@
1
+ # em-serialport
2
+
3
+ Eventmachine compatible asynchronous, ruby-serialport library.
4
+
5
+ ## Installation
6
+
7
+ In Gemfile
8
+
9
+ gem 'em-serialport', :git => 'git@github.com:railsbob/em-serialport.git'
10
+
11
+ ## Usage
12
+
13
+ If you are on Mac, you need to set up a virtual USB serial port by installing a driver from [http://www.ftdichip.com/Drivers/VCP.htm](http://www.ftdichip.com/Drivers/VCP.htm). Identify your serial port device. For ex: /dev/tty.usbserial-xxxxxxxx
14
+
15
+ EM.run do
16
+ serial = EventMachine.open_serial('/dev/tty.usbserial-xxxxxxxx', 9600, 8, 1, 0)
17
+ serial.send_data "foo"
18
+
19
+ serial.on_data do |data|
20
+ # do something with data
21
+ end
22
+ end
23
+
data/spec/echo_spec.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ # Tested with arduino echo server on USB serial port driver
4
+ describe "Echo server test" do
5
+ it "should send and receive data over serial port" do
6
+ @data = nil
7
+ serial_device = '/dev/tty.usbserial-A100QDRR'
8
+
9
+ EM.run do
10
+ serial = EventMachine.open_serial(serial_device, 9600, 8, 1, SerialPort::NONE)
11
+ serial.send_data "an"
12
+
13
+ serial.on_data do |data|
14
+ data.should == "an"
15
+ EM.stop
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe "EM::Serialport" do
4
+ it "should use pure_ruby as library_type" do
5
+ EventMachine.library_type.should eql(:pure_ruby)
6
+ end
7
+
8
+ it "should load dependencies" do
9
+ defined?(EventMachine::StreamObject).should eql("constant")
10
+ defined?(SerialPort).should eql("constant")
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'em-serialport'
5
+
6
+ RSpec.configure do |config|
7
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: em-serialport
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Anup Narkhede
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-02-01 00:00:00 +00:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: eventmachine
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - "="
28
+ - !ruby/object:Gem::Version
29
+ hash: 59
30
+ segments:
31
+ - 0
32
+ - 12
33
+ - 10
34
+ version: 0.12.10
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: serialport
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ description: ""
52
+ email:
53
+ - anup@infinitypulse.com
54
+ executables: []
55
+
56
+ extensions: []
57
+
58
+ extra_rdoc_files: []
59
+
60
+ files:
61
+ - .gitignore
62
+ - Gemfile
63
+ - Rakefile
64
+ - em-serialport.gemspec
65
+ - lib/em-serialport.rb
66
+ - lib/em-serialport/connection.rb
67
+ - lib/em-serialport/serial_port.rb
68
+ - lib/em-serialport/version.rb
69
+ - readme.md
70
+ - spec/echo_spec.rb
71
+ - spec/em_serialport_spec.rb
72
+ - spec/spec_helper.rb
73
+ has_rdoc: true
74
+ homepage: http://anup.info
75
+ licenses: []
76
+
77
+ post_install_message:
78
+ rdoc_options: []
79
+
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ hash: 3
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ requirements: []
101
+
102
+ rubyforge_project: em-serialport
103
+ rubygems_version: 1.6.2
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: EventMachine compatible serialport library
107
+ test_files:
108
+ - spec/echo_spec.rb
109
+ - spec/em_serialport_spec.rb
110
+ - spec/spec_helper.rb