Class: OpenC3::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, flow_control = :NONE, data_bits = 8) ⇒ 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, flow_control = :NONE, data_bits = 8) ⇒ SerialDriver
Returns a new instance of SerialDriver.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/openc3/io/serial_driver.rb', line 42 def initialize(port_name, baud_rate, parity = :NONE, stop_bits = 1, write_timeout = 10.0, read_timeout = nil, flow_control = :NONE, data_bits = 8) 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, 0.01, 1000, flow_control, data_bits) elsif RUBY_ENGINE == 'ruby' @driver = PosixSerialDriver.new(port_name, baud_rate, parity, stop_bits, write_timeout, read_timeout, flow_control, data_bits) else @driver = nil # JRuby Serial on Linux not currently supported end end |
Instance Method Details
#close ⇒ Object
Disconnects the driver from the comm port
78 79 80 |
# File 'lib/openc3/io/serial_driver.rb', line 78 def close @driver.close end |
#closed? ⇒ Boolean
Returns Whether the serial port has been closed.
83 84 85 |
# File 'lib/openc3/io/serial_driver.rb', line 83 def closed? @driver.closed? end |
#read ⇒ String
Returns Binary data read from the serial port.
93 94 95 |
# File 'lib/openc3/io/serial_driver.rb', line 93 def read @driver.read end |
#read_nonblock ⇒ String
Returns Binary data read from the serial port.
98 99 100 |
# File 'lib/openc3/io/serial_driver.rb', line 98 def read_nonblock @driver.read_nonblock end |
#write(data) ⇒ Object
88 89 90 |
# File 'lib/openc3/io/serial_driver.rb', line 88 def write(data) @driver.write(data) end |