ZMQ helper functions
hardware_control.base.zmq_helper module
Functions that are commonly used for ZMQ functionality; these are primarily used in ZMQAdapter and ZMQRemoteAdapter.
- hardware_control.base.zmq_helper.add_ZMQ_message_to_queue(adapter, msg: str) None
Sort the messages into different queues that have different priorities.
Since instruments can take a while to respond to a request, it can happen that there will be a large ZMQ message queue waiting for the instrument to handle the messages. In principle, this queue can also grow over time if the instrument is too slow to catch up. To avoid this we use different priorities for the ZMQ requests. A priority always needs to be defined for a request. The following options are possible:
- Priority options:
‘0’: if a new request for the same parameter arrives, the old one is dropped from the queue. These can be used for regular update requests of parameters from the instrument.
‘1’: if a new request for the same parameter arrives, the old one is dropped from the queue. These, however, are handled before any ‘0’ priority item. These are used when a a user pushes a button on a UI.
‘2’: These are handled first and are never dropped from the queue. Usefule for automatted scanning.
- hardware_control.base.zmq_helper.check_adapter_online(adapter) None
Report change in online status to app.
- hardware_control.base.zmq_helper.handle_ZMQ_message_from_app(adapter) None
Parse and handle a ZMQ messsage from the main app.
The function first parses the message and then, depending on the message’s content, executes a command, reads a value, or sets a value in the instrument.
The possible messages have the following form:
- <instrument name> <priority> command <command name>
This triggers a command
- <instrument name> <priority> get <parameter>
This triggers a read request of the parameter
- <instrument name> <priority> set <parameter> <value>
This set a parameter to a new value
When arriving at this function the first two arguments are already taken care of and have been removed from the incoming msg.
When reading a value, the return ZMQ message has the form:
- <instrument name> <parameter> <value>
This returns a parameter value from the instrument
- Parameters:
adapter – the ZMQAdapter/ZMQRemoteAdapter for the instrument driver
msg – the ZMQ message received by the adapter