hvl_ccb.dev.base

Inheritance diagram of hvl_ccb.dev.base

Module with base classes for devices.

class Device(dev_config=None)[source]

Bases: ConfigurationMixin, 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 DeviceError[source]

Bases: CCBError

exception DeviceExistingError[source]

Bases: DeviceError

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

exception DeviceFailuresError(failures: dict[str, Exception], *args)[source]

Bases: DeviceError

Error to indicate that one or several devices failed.

failures: dict[str, Exception]

A dictionary of named devices failures (exceptions).

class DeviceSequenceMixin(devices: dict[str, Device])[source]

Bases: 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: 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:

DeviceExistingError

devices_failed_start: dict[str, 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, 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) 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, 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) 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:

DeviceFailuresError – if one or several devices failed to start

stop() None[source]

Stop all devices in this sequence in their reverse order.

Raises:

DeviceFailuresError – 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: Device, 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[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.