cehoffman-ruby-serialport 0.7.0

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/lib/serialport.rb ADDED
@@ -0,0 +1,60 @@
1
+ #--
2
+ # ruby-serialport - ruby extension to system serial port
3
+ # Copyright (C) 2008 Chris Hoffman, Danniel E. Shipton
4
+ #
5
+ # This program is free software; you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation; either version 2 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License along
16
+ # with this program; if not, write to the Free Software Foundation, Inc.,
17
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
+ #++
19
+
20
+ require "serialport.so"
21
+
22
+ # = SerialPort Class
23
+ # The SerialPort class is a loose wrapper around C functions for interfacing
24
+ # with RS232 serial ports.
25
+ class SerialPort
26
+ private_class_method(:create)
27
+
28
+ # Create a new instance of SerialPort referencing a particular system
29
+ # RS232 port. On *nix systems this is usually found under <code>/dev</code>
30
+ # as a <code>tty</code> device. In windows this is a COM* port such as
31
+ # <code>COM1</code>.
32
+ def SerialPort::new(port, *params)
33
+ sp = create(port)
34
+ begin
35
+ sp.set_modem_params(*params)
36
+ rescue
37
+ sp.close
38
+ raise
39
+ end
40
+ return sp
41
+ end
42
+
43
+ # Like new, this opens a port on the system. Open has been designed for
44
+ # block usage/short temporary access to a serial port.
45
+ def SerialPort::open(port, *params) # :yields: serialport
46
+ sp = create(port)
47
+ begin
48
+ sp.set_modem_params(*params)
49
+ if (block_given?)
50
+ yield sp
51
+ sp.close
52
+ return nil
53
+ end
54
+ rescue
55
+ sp.close
56
+ raise
57
+ end
58
+ return sp
59
+ end
60
+ end
data/test/miniterm.rb ADDED
@@ -0,0 +1,25 @@
1
+ require "../serialport.so"
2
+
3
+
4
+ if ARGV.size < 4
5
+ STDERR.print <<EOF
6
+ Usage: ruby #{$0} num_port bps nbits stopb
7
+ EOF
8
+ exit(1)
9
+ end
10
+
11
+ sp = SerialPort.new(ARGV[0].to_i, ARGV[1].to_i, ARGV[2].to_i, ARGV[3].to_i, SerialPort::NONE)
12
+
13
+ open("/dev/tty", "r+") { |tty|
14
+ tty.sync = true
15
+ Thread.new {
16
+ while true do
17
+ tty.printf("%c", sp.getc)
18
+ end
19
+ }
20
+ while (l = tty.gets) do
21
+ sp.write(l.sub("\n", "\r"))
22
+ end
23
+ }
24
+
25
+ sp.close
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cehoffman-ruby-serialport
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.0
5
+ platform: ruby
6
+ authors:
7
+ - Guillaume Pierronnet
8
+ - Alan Stern
9
+ - Daniel E. Shipton
10
+ - Chris Hoffman
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+
15
+ date: 2008-08-13 00:00:00 -07:00
16
+ default_executable:
17
+ dependencies: []
18
+
19
+ description: Ruby/SerialPort is a Ruby library that provides a class for using RS-232 serial ports.
20
+ email: cehoffman@gmail.com
21
+ executables: []
22
+
23
+ extensions:
24
+ - ext/extconf.rb
25
+ extra_rdoc_files:
26
+ - LICENSE
27
+ - CHANGELOG
28
+ - README.rdoc
29
+ files:
30
+ - LICENSE
31
+ - CHANGELOG
32
+ - README.rdoc
33
+ - lib/serialport.rb
34
+ - ext/extconf.rb
35
+ - ext/serialport.c
36
+ - ext/serialport.h
37
+ - ext/posix_serialport_impl.c
38
+ - ext/win_serialport_impl.c
39
+ - test/miniterm.rb
40
+ has_rdoc: true
41
+ homepage: http://github.com/chrishoffman/ruby-serialport/
42
+ post_install_message:
43
+ rdoc_options:
44
+ - --main
45
+ - README.rdoc
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ requirements: []
61
+
62
+ rubyforge_project:
63
+ rubygems_version: 1.2.0
64
+ signing_key:
65
+ specification_version: 2
66
+ summary: Ruby/SerialPort is a Ruby library that provides a class for using RS-232 serial ports.
67
+ test_files:
68
+ - test/miniterm.rb