Class: SerialPort
- Defined in:
- lib/extensions/serialport/serialport.rb,
lib/extensions/serialport/serialport/version.rb
Overview
This class is used for communication over a serial port. In addition to the methods here, you can use Ruby IO methods, e.g. read, write, getc, readlines, etc.
Constant Summary collapse
- VERSION =
"1.3.1"
Class Method Summary collapse
-
.new(port, *params) ⇒ SerialPort
Creates a serial port object.
-
.open(port, *params) {|serial_port| ... } ⇒ Object
This behaves like SerialPort#new, except that you can pass a block to which the new serial port object will be passed.
Class Method Details
.new(port, *params) ⇒ SerialPort .new(port, *params) ⇒ SerialPort
Creates a serial port object. Accepts the port identifier and a variable list for configuration as paramaters or hash. Please see SerialPort#set_modem_params
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/extensions/serialport/serialport.rb', line 24 def SerialPort::new(port, *params) sp = create(port) begin sp.set_modem_params(*params) rescue sp.close raise end return sp end |
.open(port, *params) {|serial_port| ... } ⇒ Object
This behaves like SerialPort#new, except that you can pass a block to which the new serial port object will be passed. In this case the connection is automaticaly closed when the block has finished.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/extensions/serialport/serialport.rb', line 42 def SerialPort::open(port, *params) sp = create(port) begin sp.set_modem_params(*params) rescue sp.close raise end if (block_given?) begin yield sp ensure sp.close end return nil end return sp end |