msl.equipment.connection_socket module

Base classes for equipment that is connected through a socket.

class msl.equipment.connection_socket.ConnectionSocket(record)[source]

Bases: ConnectionMessageBased

Base class for equipment that is connected through a socket.

The properties for a socket connection supports the following key-value pairs in the Connections Database (see also socket for more details):

'buffer_size': int, the maximum number of bytes to read at a time [default: 4096]
'encoding': str, the encoding to use [default: 'utf-8']
'encoding_errors': str, encoding error handling scheme, e.g. 'strict', 'ignore' [default: 'strict']
'family': str, the address family, e.g., 'INET', 'INET6', 'IPX' [default: 'INET']
'max_read_size': int, the maximum number of bytes that can be read [default: 1 MB]
'proto': int, the socket protocol number [default: 0]
'read_termination': str or None, read until this termination sequence is found [default: '\n']
'rstrip': bool, whether to remove trailing whitespace from "read" messages [default: False]
'socket_type': str, the socket type, e.g. 'STREAM', 'DGRAM' [default: 'STREAM']
'termination': shortcut for setting both 'read_termination' and 'write_termination' to this value
'timeout': float or None, the timeout (in seconds) for read and write operations [default: None]
'write_termination': str or None, termination sequence appended to write messages [default: '\r\n']

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 byte_buffer

Returns the reference to the byte buffer.

Type:

bytearray

property host

The host (IP address).

Type:

str

property port

The port number.

Type:

int

property socket

The reference to the socket.

Type:

socket

static parse_address(address)[source]

Get the host and port from an address.

Parameters:

address (str) – The address of a ConnectionRecord.

Returns:

dict or None – The value of the host and the port or None if address is not valid for a socket.

disconnect()[source]

Close the socket.

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.