PdCom5 Subscriber¶
-
class
pdcom5.
Transmission
(period)¶ Specifies how a variable is transferred to the client.
- Parameters
period (datetime.timedelta) – Periodic transmission.
-
class
pdcom5.
SubscriberBase
(process, transmission: pdcom5._PdComWrapper.Transmission)¶ -
newValues
() → AsyncContextManager[datetime.timedelta]¶ Entry point for library users to process incoming data.
This function return an asynchronous context manager. In the body of the context manager, the values of the subscriptions assigned to this subscriber are guaranteed to not change. The handle returned by the context manager (
async with ... as ts
) is the timestamp of the values as timedelta instance.The following example shows how to subscribe to two variables with a period of one second.
import pdcom5 process = pdcom5.Process() await process.connect("msr://localhost") subscriber = process.create_subscriber(1.0) cos = await subscriber.subscribe("/osc/cos") sin = await subscriber.subscribe("/osc/sin") running = True while running: async with subscriber.newValues() as timestamp: print(f"At {timestamp}, cos was {cos.value}" + f" and sin was {sin.value}.")
Please do not do any blocking operations in the body of the context manager, like sleeping for a long time. The reason is that the library has to cache the incoming values in some cases to make sure no data is skipped. Also, using the same subscription in multiple concurrent tasks is not allowed, for the same reason. Just create one subscriber per task.
-
-
class
pdcom5.
Subscriber
(process, transmission: pdcom5._PdComWrapper.Transmission)¶ Variable subscriber.
This class manages how variables are subscribed and the callback when new values are received.
- Parameters
process – Process instance
transmission – Kind of subscription (poll, event based, periodic)
-
async
subscribe
(variable: Union[str, pdcom5._PdComWrapper.Variable], selector: Optional[pdcom5._PdComWrapper.Selector] = None) → pdcom5.Subscription.Subscription¶ Subscribe to a variable.
- Parameters
variable – Variable to subscribe.
selector – Optional selector to create a view on multidimensional data.
- Returns
a Subscription instance.