Skip to content
Brendan Whitfield edited this page Mar 22, 2015 · 3 revisions

After installing the library, simply import obd, and create a new OBD connection object. By default, python-OBD will scan for Bluetooth and USB serial ports (in that order), and will pick the first connection it finds. The port can also be specified manually by passing a connection string to the OBD constructor. You can also use the scanSerial helper retrieve a list of connected ports.

import obd

connection = obd.OBD() # auto connect

# OR

connection = obd.OBD("/dev/ttyUSB0") # create connection with USB 0

# OR

ports = obd.scanSerial()       # return list of valid USB or RF ports
print ports                    # ['/dev/ttyUSB0', '/dev/ttyUSB1']
connection = obd.OBD(ports[0]) # connect to the first port in the list

Methods

OBD.query(command, force=False)

Sends an OBDCommand to the car, and returns a Response object. This function will block until a response is recieved from the car. This function will also check whether the given command is supported by your car. If a command is not marked as supported, it will not be sent to the car, and an empty Response will be returned. To force an unsupported command to be sent, there is an optional force parameter for your convenience.

For non-blocking querying, see Async Querying


OBD.is_connected()

Returns a boolean for whether a connection was established.


OBD.get_port_name()

Returns the string name for the currently connected port ("/dev/ttyUSB0"). If no connection was made, this function returns "Not connected to any port".


OBD.supports(command)

Returns a boolean for whether a command is supported by both the car and python-OBD


OBD.close()

Closes the connection.

Properties

OBD.supported_commands

A list of commands supported by the car.