Events
The library provides a way to act upon events coming from devices or connections.
In typical scenarios, we advise against subscribing to events and using them to control the flow of the application. The use events require thread synchronization in all languages except JavaScript. Failure to synchronize threads will likely result in intermittent and hard-to-diagnose issues.
Additionally, the events typically don't provide additional information on top of function calls.
For example, the library already uses ASCII Protocol alerts internally to determine the device's status during movement function calls.
In another example, the Disconnected event may not be raised in several cases, such as when the device connected to the serial port loses power.
The only reliable way to check the connection status is to talk to the device and catch any potential exceptions.
In Python, the events are provided through the RxPy library. See the following example on how to subscribe to an event source.
connection.alert.subscribe(lambda alert: print('Alert from device:', alert))
Note that the library invokes events using a dedicated ThreadPoolExecutor.
For that reason, you must use thread synchronization primitives such as concurrent.futures.Future to interact with events.
Reference
For more information on alerts, please visit:
API Reference:
- Connection's
alertevent AlertEvent- Connection's
disconnectedevent