hvl_ccb.dev.base

Inheritance diagram of hvl_ccb.dev.base

Module with base classes for devices.

class Device(dev_config=None)[source]

Bases: hvl_ccb.configuration.ConfigurationMixin, abc.ABC

Base class for devices. Implement this class for a concrete device, such as measurement equipment or voltage sources.

Specifies the methods to implement for a device.

static config_cls()[source]

Return the default configdataclass class.

Returns

a reference to the default configdataclass class

abstract start() None[source]

Start or restart this Device. To be implemented in the subclass.

abstract stop() None[source]

Stop this Device. To be implemented in the subclass.

exception DeviceExistingException[source]

Bases: Exception

Exception to indicate that a device with that name already exists.

exception DeviceFailuresException(failures: Dict[str, Exception], *args)[source]

Bases: Exception

Exception to indicate that one or several devices failed.

failures: Dict[str, Exception]

A dictionary of named devices failures (exceptions).

class DeviceSequenceMixin(devices: Dict[str, hvl_ccb.dev.base.Device])[source]

Bases: abc.ABC

Mixin that can be used on a device or other classes to provide facilities for handling multiple devices in a sequence.

add_device(name: str, device: hvl_ccb.dev.base.Device) None[source]

Add a new device to the device sequence.

Parameters
  • name – is the name of the device.

  • device – is the instantiated Device object.

Raises

DeviceExistingException

devices_failed_start: Dict[str, hvl_ccb.dev.base.Device]

Dictionary of named device instances from the sequence for which the most recent start() attempt failed.

Empty if stop() was called last; cf. devices_failed_stop.

devices_failed_stop: Dict[str, hvl_ccb.dev.base.Device]

Dictionary of named device instances from the sequence for which the most recent stop() attempt failed.

Empty if start() was called last; cf. devices_failed_start.

get_device(name: str) hvl_ccb.dev.base.Device[source]

Get a device by name.

Parameters

name – is the name of the device.

Returns

the device object from this sequence.

get_devices() List[Tuple[str, hvl_ccb.dev.base.Device]][source]

Get list of name, device pairs according to current sequence.

Returns

A list of tuples with name and device each.

remove_device(name: str) hvl_ccb.dev.base.Device[source]

Remove a device from this sequence and return the device object.

Parameters

name – is the name of the device.

Returns

device object or None if such device was not in the sequence.

Raises

ValueError – when device with given name was not found

start() None[source]

Start all devices in this sequence in their added order.

Raises

DeviceFailuresException – if one or several devices failed to start

stop() None[source]

Stop all devices in this sequence in their reverse order.

Raises

DeviceFailuresException – if one or several devices failed to stop

class EmptyConfig[source]

Bases: object

Empty configuration dataclass that is the default configuration for a Device.

clean_values()

Cleans and enforces configuration values. Does nothing by default, but may be overridden to add custom configuration value checks.

force_value(fieldname, value)

Forces a value to a dataclass field despite the class being frozen.

NOTE: you can define post_force_value method with same signature as this method to do extra processing after value has been forced on fieldname.

Parameters
  • fieldname – name of the field

  • value – value to assign

is_configdataclass = True
classmethod keys() Sequence[str]

Returns a list of all configdataclass fields key-names.

Returns

a list of strings containing all keys.

classmethod optional_defaults() Dict[str, object]

Returns a list of all configdataclass fields, that have a default value assigned and may be optionally specified on instantiation.

Returns

a list of strings containing all optional keys.

classmethod required_keys() Sequence[str]

Returns a list of all configdataclass fields, that have no default value assigned and need to be specified on instantiation.

Returns

a list of strings containing all required keys.

class SingleCommDevice(com, dev_config=None)[source]

Bases: hvl_ccb.dev.base.Device, abc.ABC

Base class for devices with a single communication protocol.

property com

Get the communication protocol of this device.

Returns

an instance of CommunicationProtocol subtype

abstract static default_com_cls() Type[hvl_ccb.comm.base.CommunicationProtocol][source]

Get the class for the default communication protocol used with this device.

Returns

the type of the standard communication protocol for this device

start() None[source]

Open the associated communication protocol.

stop() None[source]

Close the associated communication protocol.