Clients
Data/Image/Command clients: publish/subscribe communication (TCP/IPC), with connection targets set by the central configuration.
Overview
quatm/servers/clients.py provides the communication clients: the connection target is determined by the central configuration (Data / Image / Command Hub). GenericClient offers the standard send/receive interface and is suited to small data (<10k); use ImageClient for large payloads such as images.
Client classes
| Class | Connection | Description |
|---|---|---|
GenericClient | Determined by configuration | General send/receive (including numpy arrays), subscribe/unsubscribe |
DataClient | Data Hub | Publish and subscribe ordinary data |
ImageClient | Image Hub | Sending large image-scale data (send takes a numpy array directly) |
CommandClient | Command Hub | Sends control commands to drivers (the command name is folded into the topic) |
NpEncoder | — | JSON serialization of numpy types |
Key methods (GenericClient)
| Method | Description |
|---|---|
send(datadict, arr=None) | Publish data (optionally with one numpy array) |
recv() | Receive one frame: (topic, dict[, array]); returns None on timeout |
subscribe / unsubscribe | Subscribe / unsubscribe a channel |
has_new_data | Non-blocking check for new data |
close | Close the PUB/SUB socket (idempotent) |
Usage
from quatm.servers.clients import DataClient
dc = DataClient(name="pmt")
dc.send({"pmt": 1234}, arr=numpy_array)
topic, data = dc.recv()