oatmeal 0.1-universal-dotnet

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/LICENSE.txt +21 -0
  2. data/README.rst +39 -0
  3. data/lib/serialport.rb +57 -0
  4. metadata +49 -0
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2010 Ian Dees
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ =======
2
+ Oatmeal
3
+ =======
4
+
5
+ Oatmeal, "Just enough Iron in your Serial," is a Ruby library that
6
+ provides a minimal wrapper around the .NET System.IO.Ports API for
7
+ IronRuby_. It mimics the ``read`` and ``write`` methods from its more
8
+ full-featured cousin, the serialport_ Ruby library.
9
+
10
+ Prerequisites
11
+ -------------
12
+ 1. IronRuby.
13
+ 2. Mono or .NET.
14
+
15
+ Installation
16
+ ------------
17
+
18
+ ``igem install oatmeal``, or just put ``serialport.rb`` somewhere
19
+ in your ``LOAD_PATH``.
20
+
21
+ Usage
22
+ -----
23
+
24
+ Sample code::
25
+
26
+ require 'serialport'
27
+
28
+ port = SerialPort.new '/dev/ttyUSB0', 9600, 8, 1, SerialPort::NONE
29
+ port.read_timeout = 1000
30
+
31
+ begin
32
+ port.write 'something'
33
+ puts port.read
34
+ ensure
35
+ port.close
36
+ end
37
+
38
+ .. _IronRuby: http://ironruby.net
39
+ .. _serialport: http://rubygems.org/gems/serialport
@@ -0,0 +1,57 @@
1
+ class SerialPort
2
+ NONE = 0
3
+ EVEN = 1
4
+ ODD = 2
5
+
6
+ IoPorts = System::IO::Ports
7
+ IoSerialPort = IoPorts::SerialPort
8
+
9
+ attr_accessor :wait_after_send
10
+
11
+ def initialize(name, baud, data, stop, parity)
12
+ @wait_after_send = nil
13
+
14
+ io_parity = case parity
15
+ when NONE then IoPorts::Parity.None
16
+ when EVEN then IoPorts::Parity.Even
17
+ when ODD then IoPorts::Parity.Odd
18
+ end
19
+
20
+ io_stop = case stop
21
+ when 0 then IoPorts::StopBits.None
22
+ when 1 then IoPorts::StopBits.One
23
+ when 1.5 then IoPorts::StopBits.OnePointFive
24
+ when 2 then IoPorts::StopBits.Two
25
+ end
26
+
27
+ @port = IoSerialPort.new name, baud, parity, data, stop
28
+ @port.open
29
+ end
30
+
31
+ def close
32
+ @port.close
33
+ end
34
+
35
+ def putc(c)
36
+ @port.write(c)
37
+ sleep(@wait_after_send / 1000.0) if @wait_after_send
38
+ end
39
+
40
+ def getc
41
+ @port.read_byte.chr
42
+ end
43
+
44
+ def write(s)
45
+ @port.write(s)
46
+ sleep(@wait_after_send / 1000.0) if @wait_after_send
47
+ end
48
+
49
+ def read
50
+ @port.read_existing
51
+ end
52
+
53
+ def read_timeout=(ms)
54
+ @port.read_timeout = ms
55
+ end
56
+ end
57
+
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oatmeal
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: universal-dotnet
6
+ authors:
7
+ - Ian Dees
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2010-05-18 00:00:00 -07:00
12
+ default_executable:
13
+ dependencies: []
14
+ description: Provides a tiny subset of the serialport gem for IronRuby
15
+ email:
16
+ - undees@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/serialport.rb
22
+ - LICENSE.txt
23
+ - README.rst
24
+ has_rdoc: true
25
+ homepage: http://github.com/undees/oatmeal
26
+ licenses: []
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "0"
36
+ version:
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: 1.3.5
42
+ version:
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 1.3.5
46
+ signing_key:
47
+ specification_version: 3
48
+ summary: Just barely enough Iron in your Serial
49
+ test_files: []