msl.equipment.connection_zeromq module

Base class for equipment that use the ZeroMQ communication protocol.

class msl.equipment.connection_zeromq.ConnectionZeroMQ(record)[source]

Bases: ConnectionMessageBased

Base class for equipment that use the ZeroMQ communication protocol.

The properties for a ZeroMQ connection supports the following key-value pairs in the Connections Database:

'encoding': str, the encoding to use [default: 'utf-8']
'encoding_errors': str, encoding error handling scheme, e.g. 'strict', 'ignore' [default: 'strict']
'max_read_size': int, the maximum number of bytes that can be read [default: 1 MB]
'protocol': str, the ZeroMQ protocol [default: 'tcp']
'rstrip': bool, whether to remove trailing whitespace from "read" messages [default: False]
'socket_type': str, the ZeroMQ socket type [default: 'REQ']
'timeout': float or None, the timeout (in seconds) for read and write operations [default: None]

The backend value must be equal to MSL to use this class for the communication system. This is achieved by setting the value in the Backend field for a connection record in the Connections Database to be MSL.

Do not instantiate this class directly. Use the connect() method to connect to the equipment.

Parameters:

record (EquipmentRecord) – A record from an Equipment-Register Database.

Raises:

MSLConnectionError – If the socket cannot be opened.

property context

Reference to the ZeroMQ context.

Type:

Context

disconnect()[source]

Close the connection.

property host

The host (IP address).

Type:

str

property max_read_size

The maximum number of bytes that can be read().

Type:

int

static parse_address(address)[source]

Parse the address for valid ZeroMQ fields.

Parameters:

address (str) – The address of a ConnectionRecord.

Returns:

dict or None – The host and port number of the device or None if address is not valid for a ZeroMQ connection.

property port

The port number.

Type:

int

reconnect(max_attempts=1)[source]

Reconnect to the equipment.

Parameters:

max_attempts (int, optional) – The maximum number of attempts to try to reconnect with the equipment. If < 1 or None then keep trying until a connection is successful. If the maximum number of attempts has been reached then an exception is raise.

property socket

Reference to the ZeroMQ socket.

Type:

Socket