msl.equipment.connection module

Base class for establishing a connection to the equipment.

class msl.equipment.connection.Connection(record)[source]

Bases: object

Base class for establishing a connection to the equipment.

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 equipment_record

The information about the equipment.

Type

EquipmentRecord

disconnect()[source]

Disconnect from the equipment.

This method should be overridden in the subclass if the subclass must implement tasks that need to be performed in order to safely disconnect from the equipment.

For example:

  • to clean up system resources from memory (e.g., if using a manufacturer’s SDK)

  • to configure the equipment to be in a state that is safe for people working in the lab when the equipment is not in use

Note

This method gets called automatically when the Connection object gets garbage collected, which happens when the reference count is 0.

raise_exception(message)[source]

Raise an MSLConnectionError and log the error message.

Parameters

message (str or Exception) – The message to display in the exception class that was set by set_exception_class(). If an Exception object then its string representation is used as the message.

static convert_to_enum(obj, enum, prefix=None, to_upper=False, strict=True)[source]

Convert obj to an Enum.

Parameters
  • obj – Any object to be converted to the specified enum. Can be a value of member of the specified enum.

  • enum – The Enum object that obj should be converted to.

  • prefix (str, optional) – If obj is a str, then ensures that prefix is included at the beginning of obj before converting obj to the enum.

  • to_upper (bool, optional) – If obj is a str, then whether to change obj to be upper case before converting obj to the enum.

  • strict (bool, optional) – Whether errors should be raised. If False and obj cannot be converted to enum then obj is returned and the error is logged.

Returns

Enum – The enum.

Raises

ValueError – If obj is not in enum and strict is True.

static log_debug(msg, *args, **kwargs)[source]

Log a debug message.

All input parameters are passed to debug().

static log_info(msg, *args, **kwargs)[source]

Log an info message.

All input parameters are passed to info().

static log_warning(msg, *args, **kwargs)[source]

Log a warning message.

All input parameters are passed to warning().

static log_error(msg, *args, **kwargs)[source]

Log an error message.

All input parameters are passed to error().

static log_critical(msg, *args, **kwargs)[source]

Log a critical message.

All input parameters are passed to critical().

set_exception_class(handler)[source]

Set the exception-handler class for this Connection.

Parameters

handler (MSLConnectionError) – A subclass of MSLConnectionError

Raises

TypeError – If the handler is not a subclass of MSLConnectionError

static parse_address(address)[source]

Determine whether a subclass should be used to connect to the equipment.

Attention

The subclass should override this method.

Parameters

address (str) – The address of a ConnectionRecord.

Returns

dict or None – If the address is in a valid format for the subclass to be able to connect to the equipment then a dict is returned containing the information necessary to connect to the equipment. Otherwise, if the address is not valid for the subclass to be able to connect to the equipment then None is returned.