device

Base device driver module.

Device

Device(config_entry: DeviceConfigEntry, verbose: bool)

Bases: _AbstractDeviceControl, _ExtendableMixin, ABC

flowchart LR tm_devices.drivers.device.Device[Device] tm_devices.driver_mixins.device_control._abstract_device_control._AbstractDeviceControl[_AbstractDeviceControl] tm_devices.driver_mixins.shared_implementations._extension_mixin._ExtendableMixin[_ExtendableMixin] tm_devices.driver_mixins.device_control._abstract_device_control._AbstractDeviceControl --> tm_devices.drivers.device.Device tm_devices.driver_mixins.shared_implementations._extension_mixin._ExtendableMixin --> tm_devices.drivers.device.Device click tm_devices.drivers.device.Device href "" "tm_devices.drivers.device.Device" click tm_devices.driver_mixins.device_control._abstract_device_control._AbstractDeviceControl href "" "tm_devices.driver_mixins.device_control._abstract_device_control._AbstractDeviceControl" click tm_devices.driver_mixins.shared_implementations._extension_mixin._ExtendableMixin href "" "tm_devices.driver_mixins.shared_implementations._extension_mixin._ExtendableMixin"

Base device driver that all devices inherit from.

Parameters:
  • config_entry (DeviceConfigEntry) –

    A config entry object parsed by the DMConfigParser.

  • verbose (bool) –

    A boolean indicating if verbose output should be printed. If True, communication printouts will be logged with a level of INFO. If False, communication printouts will be logged with a level of DEBUG.

address property

address: str

Return the device address as defined in the config_entry.

This could be an IP address, hostname, or USB device address.

alias cached property

alias: str

Return the alias if it exists, otherwise an empty string.

command_argument_constants cached property

command_argument_constants: Any

Return the device command argument constants.

command_syntax_enabled property

command_syntax_enabled: bool

Return a string containing the syntax of the command being accessed.

This property indicates when the syntax should be returned instead of writing/querying the device and returning the result.

command_verification_enabled property

command_verification_enabled: bool

Indicate if command verification is enabled.

This property only applies to commands sent using the .commands property of the device.

Notes
  • If .enable_verification is set to False, then no verification will happen at all.
  • If .enable_verification is set to True and this property is True, then verification will happen for commands sent using the .commands property of the device.
  • If .enable_verification is set to True and this property is False, then verification will not happen for commands sent using the .commands property of the device.

commands cached property

commands: Any

Return the device commands.

config_entry cached property

config_entry: DeviceConfigEntry

Return the device config.

connection_type property

connection_type: str

Return a string indicating the connection type.

device_number property

device_number: int

Return the device number, if it was not created by the DeviceManager it will be -1.

device_type abstractmethod cached property

device_type: str

Return a string representing the device type.

enable_verification property writable

enable_verification: bool

Return the boolean which indicates if verification checks should happen.

This can be disabled after developing a script in order to increase the speed of the script.

Notes
  • If .enable_verification is set to False, then no verification of any commands sent using the .set_and_check() method will occur (the “check” portion of “set” and “check” will be skipped).
  • If .enable_verification is set to True, then verification will happen for commands sent using the .set_and_check() method (both the “set” and “check” portions will be executed).

hostname cached property

hostname: str

Return the hostname of the device or an empty string if unable to fetch that.

ip_address cached property

ip_address: str

Return the IPv4 address of the device or an empty string if unable to fetch that.

is_open property

is_open: bool

Indicate if the connection to the device is currently open.

manufacturer abstractmethod cached property

manufacturer: str

Return the manufacturer of the device.

model abstractmethod cached property

model: str

Return the full model of the device.

name cached property

name: str

Return the device name.

Usually something like “SCOPE 1”

name_and_alias cached property

name_and_alias: str

Return string for easy ID of device in console output prints.

port property

port: int | None

Return the device port, or None if the device doesn’t have a port.

serial abstractmethod cached property

serial: str

Return the serial number of the device.

series cached property

series: str

Return the series of the device.

Returns:
  • str

    The series of the device, e.g. MSO5, TSOVu, TEKSCOPE, AFG3K, AWG5200

sw_version abstractmethod cached property

sw_version: Version

Return the software version of the device.

verbose property

verbose: bool

Return the verbose attribute of the device.

add_method classmethod

add_method(method: Callable[Concatenate[Self, _P], _T]) -> None

Add a method to the class.

This class method is best used as a decorator on functions in order to add them to a class.

Examples:

>>> from tm_devices.drivers.device import Device
>>>
>>> @Device.add_method
... def print_hello(self: Device, var: str):
...     print("Hello World!")
...     print(f"I am a {self.__class__.__name__}!")
...     print(f"My var is {var}")
Parameters:

add_property classmethod

add_property(method: Callable[Concatenate[_EM, _P], _T]) -> None
add_property(
    method: None = None, /, *, is_cached: bool = False
) -> Callable[[Callable[Concatenate[_EM, _P], _T]], None]
add_property(
    method: Callable[[Self], _T] | None = None, /, *, is_cached: bool = False
) -> Callable[[Callable[[Self], _T]], None] | None

Add a property to the class.

This class method is best used as a decorator on functions in order to add them to a class.

Examples:

>>> from tm_devices.drivers.device import Device
>>>
>>> @Device.add_property
... def foo(self: Device):
...     return "bar"
>>>
>>> @Device.add_property(is_cached=True)
... def foo(self: Device):
...     return self.name + self.address
Parameters:
  • method (Callable[[Self], _T] | None, default: None ) –

    The property to add to the class.

  • is_cached (bool, default: False ) –

    Whether the property is only evaluated once and cached.

check_network_connection

check_network_connection() -> tuple[bool, str]

Check the network connection to the device using an external ping command.

Wrapper function for check_network_connection.

Returns:
  • tuple[bool, str]

    A tuple containing a boolean indicating if there is a network connection and a string with the result of the ping command.

check_port_connection

check_port_connection(port: int, timeout_seconds: int = 5) -> bool

Check if the given port is open on the device.

Wrapper function for check_port_connection.

Parameters:
  • port (int) –

    The port to check.

  • timeout_seconds (int, default: 5 ) –

    The number of seconds to use as the socket timeout.

Returns:
  • bool

    A boolean indicating if the port is open.

cleanup

cleanup(verbose: bool = True) -> None

Perform the cleanup defined for the device.

Parameters:
  • verbose (bool, default: True ) –

    Set this to False in order to disable printouts.

close

close() -> None

Close this device and all its used resources and components.

command_syntax

command_syntax() -> Generator[None, None, None]

Enable command syntax for the duration of this context manager.

This method is designed to be used as a context manager (with device.command_syntax():) around any blocks of code where the literal syntax of commands accessed using the .commands property is desired.

This is accomplished by setting the .command_syntax_enabled property to True for the duration of the context manager.

command_verification

command_verification() -> Generator[None, None, None]

Enable command verification for the duration of this context manager.

This method is designed to be used as a context manager (with device.command_verification():) around any blocks of code where verification of commands sent using the .commands property is desired.

This is accomplished by setting the .command_verification_enabled property to True for the duration of the context manager.

get_errors

get_errors() -> tuple[int, tuple[str, ...]]

Get the current errors from the device.

Note

This method will clear out the error queue after reading the current errors.

Returns:
  • tuple[int, tuple[str, ...]]

    A tuple containing the current error code alongside a tuple of the current error messages.

has_errors

has_errors() -> bool

Check if the device has any errors.

Note

This method will clear out the error queue after reading the current errors.

Returns:
  • bool

    A boolean indicating if any errors were found in the device. True means there were errors, False means no errors were found.

reboot

reboot(quiet_period: int = 0) -> bool

Reboot the device and reconnect all its used resources and components.

Parameters:
  • quiet_period (int, default: 0 ) –

    Optional sleep after the reboot in seconds.

Returns:
  • bool

    A boolean representing the status of the reboot.

temporary_enable_verification

temporary_enable_verification(temporary_enable_verification: bool) -> Generator[None, None, None]

Enable (or disable) all verification of communication for the duration of the context.

This will temporarily set the Device.enable_verification property to the specified value, and then reset it to the previous value when the context exits.

Parameters:
  • temporary_enable_verification (bool) –

    The temporary verification value (True or False).

temporary_verbose

temporary_verbose(temporary_verbose: bool) -> Generator[None, None, None]

Set a temporary console output verbosity for the duration of the context.

This will reset the verbosity to the previous value when the context exits.

Parameters:
  • temporary_verbose (bool) –

    The temporary verbosity value.

wait_for_network_connection

wait_for_network_connection(
    wait_time: float, sleep_seconds: int = 2, accept_immediate_connection: bool = False
) -> bool

Wait for a network connection to the device.

Parameters:
  • wait_time (float) –

    The number of seconds to wait for the network connection.

  • sleep_seconds (int, default: 2 ) –

    The number of seconds to sleep in between connection attempts.

  • accept_immediate_connection (bool, default: False ) –

    A boolean indicating if a connection on the first attempt is a valid connection.

Returns:
  • bool

    A boolean indicating if a network connection was made within the given time limit.

Raises:
  • AssertionError

    Indicating that the device erroneously connected on the first try.

wait_for_port_connection

wait_for_port_connection(
    port: int, wait_time: float, sleep_seconds: int = 5, accept_immediate_connection: bool = False
) -> bool

Wait for a connection to be made to the given port on the device.

Parameters:
  • port (int) –

    The port to check.

  • wait_time (float) –

    The maximum time to wait in seconds.

  • sleep_seconds (int, default: 5 ) –

    The number of seconds to sleep in between connection attempts.

  • accept_immediate_connection (bool, default: False ) –

    A boolean indicating if a connection on the first attempt is a valid connection.

Returns:
  • bool

    A boolean indicating if a connection was made to the port within the given time limit.

Raises:
  • AssertionError

    Indicating that the device erroneously connected on the first try.

family_base_class

family_base_class(cls: _T) -> _T

A decorator indicating a class is the top level of a unique product family tree.

Notes

All subclassed children will point to the decorated class.