Class: OBD::Connection
- Inherits:
-
Object
- Object
- OBD::Connection
- Defined in:
- lib/obd/connection.rb
Instance Method Summary collapse
- #[](command) ⇒ Object
- #connect ⇒ Object
-
#initialize(port, baud = 9600) ⇒ Connection
constructor
A new instance of Connection.
- #send(data) ⇒ Object
- #voltage ⇒ Object
Constructor Details
#initialize(port, baud = 9600) ⇒ Connection
Returns a new instance of Connection.
3 4 5 6 7 8 |
# File 'lib/obd/connection.rb', line 3 def initialize port, baud = 9600 @port = port @baud = baud connect end |
Instance Method Details
#[](command) ⇒ Object
25 26 27 |
# File 'lib/obd/connection.rb', line 25 def [] command OBD::Command.format_result(command, send(OBD::Command.to_hex(command))) end |
#connect ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/obd/connection.rb', line 14 def connect @serial_port = SerialPort.new @port, @baud # , data_bits: 8, stop_bits: 1, parity: SerialPort::NONE @serial_port.read_timeout = 5000 read send("AT E0") # turn echo off send("AT L0") # turn linefeeds off send("AT S0") # turn spaces off send("AT AT2") # respond to commands faster send("AT SP 00") # automatically select protocol end |
#send(data) ⇒ Object
29 30 31 32 |
# File 'lib/obd/connection.rb', line 29 def send data write data read end |
#voltage ⇒ Object
10 11 12 |
# File 'lib/obd/connection.rb', line 10 def voltage send("AT RV") end |