forked from Pbartek/pyobd-pi
-
Notifications
You must be signed in to change notification settings - Fork 372
Async Querying
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 Response
s up-to-date. This way, when the user query
s 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.
The watch()
method subscribes a command to be continuously updated. After calling watch()
, the query()
function will return the latest Response
from that command.