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:
Connection
Base class for equipment that use message-based communication.
The
backend
value must be equal toMSL
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 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
str
it 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
str
it 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_termination
byte(s) is(are) received – only ifread_termination
is notNone
.size bytes have been received – only if size is not
None
.a timeout occurs – only if
timeout
is notNone
. AnMSLTimeoutError
is raised.max_read_size
bytes have been received. AnMSLConnectionError
is raised.
- Parameters:
size (
int
, optional) – The number of bytes to read. Ignored if it isNone
.fmt (
str
orNone
, 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.dtype
supports. 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 theint
orfloat
class 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
,bytes
orndarray
– The message from the equipment. If dtype is specified, then the message is returned as anndarray
, if decode isTrue
then 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 (
str
orbytes
) – The message to write to the equipment.data (
list
,tuple
ornumpy.ndarray
, optional) – The data to append to message. Seeto_bytes()
for more details.fmt (
str
orNone
, 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()
.