Skip to content
brendanwhitfield edited this page Nov 30, 2014 · 7 revisions

Since the standard query() function is blocking, it can be a hazard for UI event loops. To deal with this, python-OBD has an Async connection object that can be used in place of the standard OBD object.

import obd

connection = obd.Async()                 # same constructor as 'obd.OBD()'

connection.watch(obd.commands.RPM)       # tell python-OBD to keep track of the RPM

print connection.query(obd.commands.RPM) # non-blocking, returns immediately

The Async connection works by maintaining a list of commands, and keeping their Responses up-to-date. This way, when the user querys the car, the latest response is returned immediately.

Async is a subclass of OBD, and therefore inherits all of the standard methods. However, Async adds a few, in order to manage the list of sensors being watched.

Async.watch()

The watch() method subscribes a command to be continuously updated. After calling watch(), the query() function will return the latest Response from that command.

Docs have been moved to python-obd.readthedocs.org

Clone this wiki locally