rubyserial 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 768694b356264952b50a41408e6aecd0e2bd0f74
4
- data.tar.gz: 6e88db468ceb626d7d66c48687873a42afb994ad
3
+ metadata.gz: 8b3a8a0b1d1fce547d243e5444499f534277d695
4
+ data.tar.gz: bfccd64bec3eb198a4f61a01a6865c4325bf4df3
5
5
  SHA512:
6
- metadata.gz: e8610224155564d6a8acc8f3f922c3ce5ed0cc7fbcde57ff3aca9ccda649f24b53bbd1df5e1986d4175f4489f5a8ff48dd48f47ab3df2cbeefa075d53943376b
7
- data.tar.gz: 6f8974af626202bb8a7f67ae28a5e25a62487cde2b06000dfcfab18d8b9fc39949dd7fcd0793ef474365c46f5f9186894abf2151c9bbe3078c06456cfe5da92c
6
+ metadata.gz: 57000058b5000c5982869e718263ee36fcf0e3cf75df50616a52e1dec3950aafc404219c85e6c9cd3e9a386600e0b9084c54e1e45e425403fdf0992a963cc8b4
7
+ data.tar.gz: a3c2e84d223ed23794f5e0f99334407b67bcd8098add2d800f379e3cf19dd82c944a3a4bf9bff7ca6666272dee0af4450cf5c574c7b461f62af407020b4248f4
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  .bundle
2
2
  /vendor
3
3
  Gemfile.lock
4
+ socat.log
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --warnings
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
6
+ - ruby-head
7
+ - jruby
8
+ - jruby-head
9
+ - rbx-2.2.10
10
+ install:
11
+ - sudo apt-get update && sudo apt-get install --force-yes socat
12
+ script:
13
+ - bundle install
14
+ - bundle exec rspec
data/Gemfile CHANGED
@@ -2,3 +2,4 @@
2
2
  source "http://rubygems.org"
3
3
 
4
4
  gemspec
5
+ gem 'rspec', '~> 3.0.0'
data/README.md CHANGED
@@ -1,27 +1,42 @@
1
1
  # rubyserial
2
2
 
3
- A simple ruby gem which allows you to read and write from a serial port.
3
+ RubySerial is a simple RubyGem for reading from and writing to serial ports.
4
+
5
+ [![Build Status](https://travis-ci.org/hybridgroup/rubyserial.svg)](https://travis-ci.org/hybridgroup/rubyserial)
6
+
7
+ ## Installation
8
+
9
+ $ gem install rubyserial
10
+
11
+ ## Usage
4
12
 
5
- Usage:
6
13
  ```ruby
7
14
  require 'rubyserial'
8
- s = Serial.new("/dev/ttyACM0", 57600)
15
+ serialport = Serial.new '/dev/ttyACM0', 57600
9
16
  ```
10
17
 
11
- #####write(string) -> int
12
- ```
13
- returns the number of bytes written.
14
- RubySerial::Exception on error.
15
- ```
16
- ######read(length) -> string
17
- ```
18
- returns a string up to "length".
19
- read is not guarenteed to return the entire "length" specified.
20
- returns "" on no data
21
- RubySerial::Exception on error.
22
- ```
18
+ ## Methods
23
19
 
24
- ######RubySerial::Exception
25
- ```
26
- returns the underlying system error code
27
- ```
20
+ **write(data : String) -> Int**
21
+
22
+ Returns the number of bytes written.
23
+ Emits a `RubySerial::Exception` on error.
24
+
25
+ **read(length : Int) -> String**
26
+
27
+ Returns a string up to `length` long. It is not guaranteed to return the entire
28
+ length specified, and will return an empty string if no data is
29
+ available. Emits a `RubySerial::Exception` on error.
30
+
31
+ **getbyte -> Fixnum or nil**
32
+
33
+ Returns an 8 bit byte or nil if no data is available.
34
+ Emits a `RubySerial::Exception` on error.
35
+
36
+ **RubySerial::Exception**
37
+
38
+ A wrapper exception type, that returns the underlying system error code.
39
+
40
+ ## License
41
+
42
+ Apache 2.0. See `LICENSE` for more details.
@@ -64,6 +64,20 @@ class Serial
64
64
  buff.get_bytes(0, i)
65
65
  end
66
66
 
67
+ def getbyte
68
+ buff = FFI::MemoryPointer.new :char, 1
69
+ i = RubySerial::Posix.read(@fd, buff, 1)
70
+ if i == -1
71
+ raise RubySerial::Exception, RubySerial::Posix::ERROR_CODES[FFI.errno]
72
+ end
73
+
74
+ if i == 0
75
+ nil
76
+ else
77
+ buff.read_string.unpack('C').first
78
+ end
79
+ end
80
+
67
81
  private
68
82
 
69
83
  def build_config(baude_rate, data_bits)
@@ -1,5 +1,5 @@
1
1
  module RubySerial
2
2
  unless const_defined?('VERSION')
3
- VERSION = "0.0.1"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -50,6 +50,21 @@ class Serial
50
50
  buff.get_bytes(0, count.read_string.unpack('H4').join().to_i(16))
51
51
  end
52
52
 
53
+ def getbyte
54
+ buff = FFI::MemoryPointer.new :char, 1
55
+ count = FFI::MemoryPointer.new :uint32, 1
56
+ err = RubySerial::Win32.ReadFile(@fd, buff, size, count, nil)
57
+ if err == 0
58
+ raise RubySerial::Exception, RubySerial::Win32::ERROR_CODES[FFI.errno]
59
+ end
60
+
61
+ if count.read_string.unpack('H4').join().to_i(16) == 0
62
+ nil
63
+ else
64
+ buff.read_string.unpack('C').first
65
+ end
66
+ end
67
+
53
68
  def write(data)
54
69
  buff = FFI::MemoryPointer.from_string(data.to_s)
55
70
  count = FFI::MemoryPointer.new :uint32, 1
data/rubyserial.gemspec CHANGED
@@ -4,8 +4,8 @@ require "rubyserial/version"
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "rubyserial"
6
6
  s.version = RubySerial::VERSION
7
- s.summary = "ffi ruby serialport gem"
8
- s.description = "ffi ruby serialport gem"
7
+ s.summary = "FFI Ruby library for RS-232 serial port communication"
8
+ s.description = "FFI Ruby library for RS-232 serial port communication"
9
9
  s.homepage = "https://github.com/hybridgroup/rubyserial"
10
10
  s.authors = ["Adrian Zankich", "Theron Boerner", "Javier Cervantes"]
11
11
  s.platform = Gem::Platform::RUBY
@@ -0,0 +1,35 @@
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
+ @sp = Serial.new(@ptys[0][0])
25
+ @sp2.write('hello')
26
+
27
+ # small delay so it can write to the other port.
28
+ sleep 0.1
29
+ end
30
+
31
+ it "should read and write" do
32
+ check = @sp.read(5)
33
+ expect(check).to eql('hello')
34
+ end
35
+ end
@@ -0,0 +1,78 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, make a
10
+ # separate helper file that requires this one and then use it only in the specs
11
+ # that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+ RSpec.configure do |config|
18
+ # The settings below are suggested to provide a good initial experience
19
+ # with RSpec, but feel free to customize to your heart's content.
20
+ =begin
21
+ # These two settings work together to allow you to limit a spec run
22
+ # to individual examples or groups you care about by tagging them with
23
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
24
+ # get run.
25
+ config.filter_run :focus
26
+ config.run_all_when_everything_filtered = true
27
+
28
+ # Many RSpec users commonly either run the entire suite or an individual
29
+ # file, and it's useful to allow more verbose output when running an
30
+ # individual spec file.
31
+ if config.files_to_run.one?
32
+ # Use the documentation formatter for detailed output,
33
+ # unless a formatter has already been configured
34
+ # (e.g. via a command-line flag).
35
+ config.default_formatter = 'doc'
36
+ end
37
+
38
+ # Print the 10 slowest examples and example groups at the
39
+ # end of the spec run, to help surface which specs are running
40
+ # particularly slow.
41
+ config.profile_examples = 10
42
+
43
+ # Run specs in random order to surface order dependencies. If you find an
44
+ # order dependency and want to debug it, you can fix the order by providing
45
+ # the seed, which is printed after each run.
46
+ # --seed 1234
47
+ config.order = :random
48
+
49
+ # Seed global randomization in this process using the `--seed` CLI option.
50
+ # Setting this allows you to use `--seed` to deterministically reproduce
51
+ # test failures related to randomization by passing the same `--seed` value
52
+ # as the one that triggered the failure.
53
+ Kernel.srand config.seed
54
+
55
+ # rspec-expectations config goes here. You can use an alternate
56
+ # assertion/expectation library such as wrong or the stdlib/minitest
57
+ # assertions if you prefer.
58
+ config.expect_with :rspec do |expectations|
59
+ # Enable only the newer, non-monkey-patching expect syntax.
60
+ # For more details, see:
61
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
62
+ expectations.syntax = :expect
63
+ end
64
+
65
+ # rspec-mocks config goes here. You can use an alternate test double
66
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
67
+ config.mock_with :rspec do |mocks|
68
+ # Enable only the newer, non-monkey-patching expect syntax.
69
+ # For more details, see:
70
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
71
+ mocks.syntax = :expect
72
+
73
+ # Prevents you from mocking or stubbing a method that does not exist on
74
+ # a real object. This is generally recommended.
75
+ mocks.verify_partial_doubles = true
76
+ end
77
+ =end
78
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyserial
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Zankich
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-07-01 00:00:00.000000000 Z
13
+ date: 2014-07-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: ffi
@@ -26,13 +26,15 @@ dependencies:
26
26
  - - "~>"
27
27
  - !ruby/object:Gem::Version
28
28
  version: 1.9.3
29
- description: ffi ruby serialport gem
29
+ description: FFI Ruby library for RS-232 serial port communication
30
30
  email:
31
31
  executables: []
32
32
  extensions: []
33
33
  extra_rdoc_files: []
34
34
  files:
35
35
  - ".gitignore"
36
+ - ".rspec"
37
+ - ".travis.yml"
36
38
  - Gemfile
37
39
  - LICENSE
38
40
  - README.md
@@ -45,6 +47,8 @@ files:
45
47
  - lib/rubyserial/windows.rb
46
48
  - lib/rubyserial/windows_constants.rb
47
49
  - rubyserial.gemspec
50
+ - spec/basic_rw_spec.rb
51
+ - spec/spec_helper.rb
48
52
  homepage: https://github.com/hybridgroup/rubyserial
49
53
  licenses:
50
54
  - Apache 2.0
@@ -68,5 +72,5 @@ rubyforge_project:
68
72
  rubygems_version: 2.2.2
69
73
  signing_key:
70
74
  specification_version: 4
71
- summary: ffi ruby serialport gem
75
+ summary: FFI Ruby library for RS-232 serial port communication
72
76
  test_files: []