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.
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 76 77 78 79 80 81 |
# File 'lib/openc3/io/serial_driver.rb', line 48 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
84 85 86 |
# File 'lib/openc3/io/serial_driver.rb', line 84 def close @driver.close end |
#closed? ⇒ Boolean
Returns Whether the serial port has been closed.
89 90 91 |
# File 'lib/openc3/io/serial_driver.rb', line 89 def closed? @driver.closed? end |
#read ⇒ String
Returns Binary data read from the serial port.
99 100 101 |
# File 'lib/openc3/io/serial_driver.rb', line 99 def read @driver.read end |
#read_nonblock ⇒ String
Returns Binary data read from the serial port.
104 105 106 |
# File 'lib/openc3/io/serial_driver.rb', line 104 def read_nonblock @driver.read_nonblock end |
#write(data) ⇒ Object
94 95 96 |
# File 'lib/openc3/io/serial_driver.rb', line 94 def write(data) @driver.write(data) end |