Skip to content
brendanwhitfield edited this page Dec 1, 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

Async is a subclass of OBD, and therefore inherits all of the standard methods. However, Async adds a few, in order to manage a list of sensors (commands) being watched. It 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.

watch()

Async.watch(OBDCommand, <force>)

The watch() method subscribes a command to be continuously updated. After calling watch(), the query() function will return the latest Response from that command. An optional force parameter will force an unsupported command to be sent.

unwatch()

Async.unwatch(OBDCommand)

Unsubscribes a command from being updated.

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

Clone this wiki locally