-
Notifications
You must be signed in to change notification settings - Fork 380
Async Querying
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.
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 commands and responses. This way, when the user query
s the car, the latest response is returned immediately. Callbacks can also be specified, and will return new Response
s when available.
import obd
connection = obd.Async() # same constructor as 'obd.OBD()'
connection.watch(obd.commands.RPM) # tell python-OBD to keep track of the RPM
connection.start() # start the async update loop
print connection.query(obd.commands.RPM) # non-blocking, returns immediately
Starts the update loop.
Stops the update loop.
Note: The async loop must be stopped before this function can be called
Subscribes a command to be continuously updated. After calling watch()
, the query()
function will return the latest Response
from that command. An optional callback can also be set, and will be fired upon receipt of new values. Multiple callbacks for the same command are welcome. An optional force
parameter will force an unsupported command to be sent.
Note: The async loop must be stopped before this function can be called
Unsubscribes a command from being updated. If no callback is specified, all callbacks are dropped. If a callback is given, only that callback is unsubscribed (all other callbacks remain live).
Note: The async loop must be stopped before this function can be called
Unsubscribes all commands and callbacks.