msl.equipment.connection_message_based module
Base class for equipment that use message-based communication.
- class msl.equipment.connection_message_based.ConnectionMessageBased(record)[source]
Bases:
ConnectionBase class for equipment that use message-based communication.
The
backendvalue must be equal toMSLto 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 beMSL.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.
- property encoding_errors
The error handling scheme to use when encoding and decoding messages.
For example: strict, ignore, replace, xmlcharrefreplace, backslashreplace
- Type:
- property read_termination
The termination character sequence that is used for the
read()method.Reading stops when the equipment stops sending data or the read_termination character sequence is detected. If you set the read_termination to be equal to a variable of type
strit will automatically be encoded.
- property write_termination
The termination character sequence that is appended to
write()messages.If you set the write_termination to be equal to a variable of type
strit will automatically be encoded.
- property timeout
The timeout, in seconds, for
read()andwrite()operations.A value \(\lt\) 0 will set the timeout to be
None(blocking mode).
- raise_timeout(append_msg='')[source]
Raise a
MSLTimeoutError.- Parameters:
append_msg (
str, optional) – A message to append to the generic timeout message.
- read(size=None, fmt='ascii', dtype=None, decode=True)[source]
Read a message from the equipment.
This method will block until one of the following conditions is fulfilled:
the
read_terminationbyte(s) is(are) received – only ifread_terminationis notNone.size bytes have been received – only if size is not
None.a timeout occurs – only if
timeoutis notNone. AnMSLTimeoutErroris raised.max_read_sizebytes have been received. AnMSLConnectionErroris raised.
- Parameters:
size (
int, optional) – The number of bytes to read. Ignored if it isNone.fmt (
strorNone, optional) – The format that the message data is in. Ignored if dtype is not specified. Seefrom_bytes()for more details.dtype – The data type of the elements in the message data. Can be any object that
numpy.dtypesupports. Seefrom_bytes()for more details. For messages that are of scalar type (i.e., a single number) it is more efficient to not specify dtype but to pass the message to theintorfloatclass to convert the message to the appropriate numeric type.decode (
bool, optional) – Whether to decode the message (i.e., convert the message to astr) or keep the message asbytes. Ignored if dtype is specified.
- Returns:
str,bytesorndarray– The message from the equipment. If dtype is specified, then the message is returned as anndarray, if decode isTruethen the message is returned as astr, otherwise the message is returned asbytes.
See also
- write(message, data=None, fmt='ieee', dtype='<f')[source]
Write a message to the equipment.
- Parameters:
message (
strorbytes) – The message to write to the equipment.data (
list,tupleornumpy.ndarray, optional) – The data to append to message. Seeto_bytes()for more details.fmt (
strorNone, optional) – The format to use to convert data to bytes. Ignored if data isNone. Seeto_bytes()for more details.dtype – The data type to use to convert each element in data to bytes. Ignored if data is
None. Seeto_bytes()for more details.
- Returns:
int– The number of bytes written.
- query(message, delay=0.0, **kwargs)[source]
Convenience method for performing a
write()followed by aread().