Class: Cosmos::SerialDriver
Overview
A platform independent serial driver
Constant Summary collapse
Instance Method Summary collapse
-
#close ⇒ Object
Disconnects the driver from the comm port.
-
#closed? ⇒ Boolean
Whether the serial port has been closed.
-
#initialize(port_name, baud_rate, parity = :NONE, stop_bits = 1, write_timeout = 10.0, read_timeout = nil) ⇒ SerialDriver
constructor
A new instance of SerialDriver.
-
#read ⇒ String
Binary data read from the serial port.
-
#read_nonblock ⇒ String
Binary data read from the serial port.
- #write(data) ⇒ Object
Constructor Details
#initialize(port_name, baud_rate, parity = :NONE, stop_bits = 1, write_timeout = 10.0, read_timeout = nil) ⇒ SerialDriver
Returns a new instance of SerialDriver.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/cosmos/io/serial_driver.rb', line 34 def initialize(port_name, baud_rate, parity = :NONE, stop_bits = 1, write_timeout = 10.0, read_timeout = nil) raise(ArgumentError, "Invalid parity: #{parity}") unless VALID_PARITY.include? parity if Kernel.is_windows? @driver = Win32SerialDriver.new(port_name, baud_rate, parity, stop_bits, write_timeout, read_timeout) else @driver = PosixSerialDriver.new(port_name, baud_rate, parity, stop_bits, write_timeout, read_timeout) end end |
Instance Method Details
#close ⇒ Object
Disconnects the driver from the comm port
59 60 61 |
# File 'lib/cosmos/io/serial_driver.rb', line 59 def close @driver.close end |
#closed? ⇒ Boolean
Returns Whether the serial port has been closed.
64 65 66 |
# File 'lib/cosmos/io/serial_driver.rb', line 64 def closed? @driver.closed? end |
#read ⇒ String
Returns Binary data read from the serial port.
74 75 76 |
# File 'lib/cosmos/io/serial_driver.rb', line 74 def read @driver.read end |
#read_nonblock ⇒ String
Returns Binary data read from the serial port.
79 80 81 |
# File 'lib/cosmos/io/serial_driver.rb', line 79 def read_nonblock @driver.read_nonblock end |
#write(data) ⇒ Object
69 70 71 |
# File 'lib/cosmos/io/serial_driver.rb', line 69 def write(data) @driver.write(data) end |