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
ofCalibrationRecord
) – 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
ofMaintenanceRecord
) – 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:
- calibrations
The calibration history of the equipment.
- Type:
- maintenances
The maintenance history of the equipment.
- Type:
- connection
The information necessary to communicate with the equipment.
- Type:
- user_defined
User-defined, key-value pairs.
- Type:
- 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 theDEMO_MODE
attribute.- Returns:
A
Connection
subclass.
- is_calibration_due(months: int = 0) bool [source]
Whether the equipment needs to be re-calibrated.
- Parameters:
months – 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:
True
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:
- next_calibration_date() date | None [source]
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 adict
.- Returns:
dict
– TheEquipmentRecord
as adict
.
- to_json()[source]
Convert this
EquipmentRecord
to be JSON serializable.- Returns:
dict
– TheEquipmentRecord
as a JSON-serializable object.
- to_xml()[source]
Convert this
EquipmentRecord
to an XMLElement
.- Returns:
Element
– TheEquipmentRecord
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
orfloat
) – The number of years that can pass before the equipment must be re-calibrated.calibration_date (
datetime.date
,datetime.datetime
orstr
) – The date that the calibration was performed. If astr
then in the format'YYYY-MM-DD'
.measurands (
list
ofMeasurandRecord
) – The quantities that were measured.report_date (
datetime.date
,datetime.datetime
orstr
) – The date that the report was issued. If astr
then in the format'YYYY-MM-DD'
.report_number (
str
) – The report number.
- calibration_cycle
The number of years that can pass before the equipment must be re-calibrated.
- Type:
- calibration_date
The date that the calibration was performed.
- Type:
- measurands
The quantities that were measured.
- Type:
- report_date
The date that the report was issued.
- Type:
- to_json()[source]
Convert this
CalibrationRecord
to be JSON serializable.- Returns:
dict
– TheCalibrationRecord
as a JSON-serializable object.
- to_xml()[source]
Convert this
CalibrationRecord
to an XMLElement
.- Returns:
Element
– TheCalibrationRecord
as a XMLElement
.
- 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, %, …).
- calibration
The information about calibration.
- Type:
- conditions
The information about the measurement conditions.
- Type:
- to_json()[source]
Convert this
MeasurandRecord
to be JSON serializable.- Returns:
dict
– TheMeasurandRecord
as a JSON-serializable object.
- to_xml()[source]
Convert this
MeasurandRecord
to an XMLElement
.- Returns:
Element
– TheMeasurandRecord
as a XMLElement
.
- 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 (
str
) – A description of the maintenance that was performed.date (
datetime.date
,datetime.datetime
orstr
) – An object that can be converted to adatetime.date
object. If astr
then in the format'YYYY-MM-DD'
.
- date
The date that the maintenance was performed.
- Type:
- to_json()[source]
Convert this
MaintenanceRecord
to be JSON serializable.- Returns:
dict
– TheMaintenanceRecord
as a JSON-serializable object.
- to_xml()[source]
Convert this
MaintenanceRecord
to an XMLElement
.- Returns:
Element
– TheMaintenanceRecord
as a XMLElement
.
- 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
, orBackend
) – The backend to use to communicate with the equipment. The value must be able to be converted to aBackend
enum.interface (
str
,int
, orInterface
) – The interface to use to communicate with the equipment. IfNone
then determines the interface based on the value of address. If specified then the value must be able to be converted to aInterface
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:
- interface
The interface that is used for the communication system that transfers data between a computer and the equipment (only used if the
backend
is equal toMSL
).- Type:
- 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:
- to_json()[source]
Convert this
ConnectionRecord
to be JSON serializable.- Returns:
dict
– TheConnectionRecord
as a JSON-serializable object.
- to_xml()[source]
Convert this
ConnectionRecord
to an XMLElement
.- Returns:
Element
– TheConnectionRecord
as a XMLElement
.
- 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 theRecordDict
.
- to_xml(tag='RecordDict')[source]
Convert the
RecordDict
to an XMLElement
- Parameters:
- Returns:
Element
– TheRecordDict
as an XMLElement
.
- to_json()[source]
dict
: Convert theRecordDict
to be JSON serializable.