msl.equipment.record_types module

Records from Equipment-Register Database's or Connections Database's.

class msl.equipment.record_types.EquipmentRecord(alias='', calibrations=None, category='', connection=None, description='', is_operable=False, maintenances=None, manufacturer='', model='', serial='', team='', unique_key='', **user_defined)[source]

Bases: Record

Contains the information about an equipment record in an Equipment-Register Database.

Parameters
  • alias (str) – An alias to use to reference this equipment by.

  • calibrations (list of CalibrationRecord) – The calibration history of the equipment.

  • category (str) – The category (e.g., Laser, DMM) that the equipment belongs to.

  • connection (ConnectionRecord) – The information necessary to communicate with the equipment.

  • description (str) – A description about the equipment.

  • is_operable (bool) – Whether the equipment is able to be used.

  • maintenances (list of MaintenanceRecord) – The maintenance history of the equipment.

  • manufacturer (str) – The name of the manufacturer of the equipment.

  • model (str) – The model number of the equipment.

  • serial (str) – The serial number (or unique identifier) of the equipment.

  • team (str) – The team (e.g., Light Standards) that the equipment belongs to.

  • unique_key (str) – The key that uniquely identifies the equipment record in a database.

  • **user_defined – All additional key-value pairs are added to the user_defined attribute.

alias

An alias to use to reference this equipment by.

The alias can be defined in 4 ways:

  • by specifying it when the EquipmentRecord is created

  • by setting the value after the EquipmentRecord has been created

  • in the <equipment> XML tag in a Configuration File

  • in the Properties field in a Connections Database

Type

str

calibrations

The calibration history of the equipment.

Type

tuple of CalibrationRecord

category

The category (e.g., Laser, DMM) that the equipment belongs to.

Type

str

description

A description about the equipment.

Type

str

is_operable

Whether the equipment is able to be used.

Type

bool

maintenances

The maintenance history of the equipment.

Type

tuple of MaintenanceRecord

manufacturer

The name of the manufacturer of the equipment.

Type

str

model

The model number of the equipment.

Type

str

serial

The serial number (or unique identifier) of the equipment.

Type

str

connection

The information necessary to communicate with the equipment.

Type

ConnectionRecord

team

The team (e.g., Light Standards) that the equipment belongs to.

Type

str

unique_key

The key that uniquely identifies the equipment record in a database.

Type

str

user_defined

User-defined, key-value pairs.

Type

RecordDict

connect(demo=None)[source]

Establish a connection to the equipment.

Calls the connect() function.

Parameters

demo (bool, optional) –

Whether to simulate a connection to the equipment by opening a connection in demo mode. This allows you to test your code if the equipment is not physically connected to a computer.

If None then the demo value is determined from the DEMO_MODE attribute.

Returns

A Connection subclass.

is_calibration_due(months=0)[source]

Whether the equipment needs to be re-calibrated.

Parameters

months (int, optional) – The number of months to add to today’s date to determine if the equipment needs to be re-calibrated within a certain amount of time. For example, if months = 6 then that is a way of asking “is a re-calibration due within the next 6 months?”.

Returns

boolTrue if the equipment needs to be re-calibrated, False if it does not need to be re-calibrated (or it has never been calibrated).

property latest_calibration

The latest calibration or None if the equipment has never been calibrated.

Type

CalibrationRecord

next_calibration_date()[source]

The date that the next calibration is due.

Returns

datetime.date – The next calibration date (or None if the equipment has never been calibrated or if it is no longer in operation).

to_dict()[source]

Convert this EquipmentRecord to a dict.

Returns

dict – The EquipmentRecord as a dict.

to_json()[source]

Convert this EquipmentRecord to be JSON serializable.

Returns

dict – The EquipmentRecord as a JSON-serializable object.

to_xml()[source]

Convert this EquipmentRecord to an XML Element.

Returns

Element – The EquipmentRecord as an XML element.

class msl.equipment.record_types.CalibrationRecord(calibration_cycle=0, calibration_date=None, measurands=None, report_date=None, report_number='')[source]

Bases: Record

Contains the information about a calibration record in an Equipment-Register Database.

Parameters
  • calibration_cycle (int or float) – The number of years that can pass before the equipment must be re-calibrated.

  • calibration_date (datetime.date, datetime.datetime or str) – The date that the calibration was performed. If a str then in the format 'YYYY-MM-DD'.

  • measurands (list of MeasurandRecord) – The quantities that were measured.

  • report_date (datetime.date, datetime.datetime or str) – The date that the report was issued. If a str then in the format 'YYYY-MM-DD'.

  • report_number (str) – The report number.

to_dict()

dict: Convert the Record to a dict.

calibration_cycle

The number of years that can pass before the equipment must be re-calibrated.

Type

float

calibration_date

The date that the calibration was performed.

Type

datetime.date

measurands

The quantities that were measured.

Type

RecordDict

report_date

The date that the report was issued.

Type

datetime.date

report_number

The report number.

Type

str

to_json()[source]

Convert this CalibrationRecord to be JSON serializable.

Returns

dict – The CalibrationRecord as a JSON-serializable object.

to_xml()[source]

Convert this CalibrationRecord to an XML Element.

Returns

Element – The CalibrationRecord as a XML Element.

class msl.equipment.record_types.MeasurandRecord(calibration=None, conditions=None, type='', unit='')[source]

Bases: Record

Contains the information about a measurement for a calibration.

Parameters
  • calibration (dict) – The information about the calibration.

  • conditions (dict) – The information about the conditions under which the measurement was performed.

  • type (str) – The type of measurement (e.g., voltage, temperature, transmittance, …).

  • unit (str) – The unit that is associated with the measurement (e.g., V, deg C, %, …).

to_dict()

dict: Convert the Record to a dict.

calibration

The information about calibration.

Type

RecordDict

conditions

The information about the measurement conditions.

Type

RecordDict

type

The type of measurement (e.g., voltage, temperature, transmittance, …).

Type

str

unit

The unit that is associated with the measurement (e.g., V, deg C, %, …).

Type

str

to_json()[source]

Convert this MeasurandRecord to be JSON serializable.

Returns

dict – The MeasurandRecord as a JSON-serializable object.

to_xml()[source]

Convert this MeasurandRecord to an XML Element.

Returns

Element – The MeasurandRecord as a XML Element.

class msl.equipment.record_types.MaintenanceRecord(comment='', date=None)[source]

Bases: Record

Contains the information about a maintenance record in an Equipment-Register Database.

Parameters
comment

A description of the maintenance that was performed.

Type

str

date

The date that the maintenance was performed.

Type

datetime.date

to_json()[source]

Convert this MaintenanceRecord to be JSON serializable.

Returns

dict – The MaintenanceRecord as a JSON-serializable object.

to_xml()[source]

Convert this MaintenanceRecord to an XML Element.

Returns

Element – The MaintenanceRecord as a XML Element.

to_dict()

dict: Convert the Record to a dict.

class msl.equipment.record_types.ConnectionRecord(address='', backend=Backend.MSL, interface=None, manufacturer='', model='', serial='', **properties)[source]

Bases: Record

Contains the information about a connection record in a Connections Database.

Parameters
  • address (str) – The address to use for the connection (see Address Syntax for examples).

  • backend (str, int, or Backend) – The backend to use to communicate with the equipment. The value must be able to be converted to a Backend enum.

  • interface (str, int, or MSLInterface) – The interface to use to communicate with the equipment. If None then determines the interface based on the value of address. If specified then the value must be able to be converted to a MSLInterface enum.

  • manufacturer (str) – The name of the manufacturer of the equipment.

  • model (str) – The model number of the equipment.

  • serial (str) – The serial number (or unique identifier) of the equipment.

  • properties – Additional key-value pairs that are required to communicate with the equipment.

address

The address to use for the connection (see Address Syntax for examples).

Type

str

backend

The backend to use to communicate with the equipment.

Type

Backend

interface
manufacturer

The name of the manufacturer of the equipment.

Type

str

model

The model number of the equipment.

Type

str

properties

Additional key-value pairs that are required to communicate with the equipment.

For example, communicating via RS-232 may require:

{'baud_rate': 19200, 'parity': 'even'}

See the Connections Database for examples on how to set the properties.

Type

dict

serial

The serial number (or unique identifier) of the equipment.

Type

str

to_json()[source]

Convert this ConnectionRecord to be JSON serializable.

Returns

dict – The ConnectionRecord as a JSON-serializable object.

to_xml()[source]

Convert this ConnectionRecord to an XML Element.

Returns

Element – The ConnectionRecord as a XML Element.

to_dict()

dict: Convert the Record to a dict.

class msl.equipment.record_types.RecordDict(dictionary)[source]

Bases: Mapping

A read-only dictionary that supports attribute access via a key lookup.

copy()[source]

RecordDict: Return a copy of the RecordDict.

to_xml(tag='RecordDict')[source]

Convert the RecordDict to an XML Element

Parameters

tag (str) – The name of the Element.

Returns

Element – The RecordDict as an XML Element.

to_json()[source]

dict: Convert the RecordDict to be JSON serializable.

class msl.equipment.record_types.Record[source]

Bases: object

to_dict()[source]

dict: Convert the Record to a dict.

to_json()[source]

dict: Convert the Record to be JSON serializable.

This differs from to_dict() such that all values that are not JSON serializable, like datetime.date objects, are converted to a str.

to_xml()[source]

Element: Convert the Record to an XML Element.