devctrl.devices.switch.impl.cleware_switch.ClewareSwitch#

class ClewareSwitch(serial_number=None, usbswitchcmd_exe_path: str | None = None)[source]#

Bases: Switch

Support for a Cleware USB Switch. The executable communicating with the device, USBSwitchCmd.exe by default, must be in the working directory or in sys.path, or the path can be provided using the usbswitchcmd_exe_path parameter.

Parameters:
  • usbswitchcmd_exe_path – Path to the usbswitchcmd executable.

  • serial_number – Serial number of the correct switch as string. Not required if only one switch is connected.

Methods

add_device

Manually add a specific device.

allow_only_dummy_devices

connect

connect_device

connect_dummy

Connect an instance of the device's dummy implementation

get_base_classes

Return a flat dictionary of all base classes below this class :param recurse: If True, recursively search for base classes :return: dict of {class name: class}

get_device_name

get_device_type_name

get_status

Query the status of the device and return a string describing errors.

is_connected

Query whether the device is (still) connected

is_on

list_devices

Get a list of all devices for this type.

off

on

run_cmd

Attributes

DEFAULT_EXE_NAME = 'USBswitchCmd.exe'#
EXE = None#
_CLASS_TYPE = 'implementation'#
__abstractmethods__ = frozenset({})#
__annotations__ = {'_manual_devices': list[str]}#
__dict__ = mappingproxy({'__module__': 'devctrl.devices.switch.impl.cleware_switch', '__firstlineno__': 8, '__doc__': '\nSupport for a Cleware USB Switch.\nThe executable communicating with the device, USBSwitchCmd.exe by default,\nmust be in the working directory or in sys.path, or the path can be provided using the usbswitchcmd_exe_path parameter.\n\n:param usbswitchcmd_exe_path: Path to the usbswitchcmd executable.\n:param serial_number: Serial number of the correct switch as string. Not required if only one switch is connected.\n', '_CLASS_TYPE': 'implementation', '__init__': <function ClewareSwitch.__init__>, 'run_cmd': <function ClewareSwitch.run_cmd>, 'is_on': <function ClewareSwitch.is_on>, 'on': <function ClewareSwitch.on>, 'off': <function ClewareSwitch.off>, 'is_connected': <function ClewareSwitch.is_connected>, '_enumerate_devices': <staticmethod(<function ClewareSwitch._enumerate_devices>)>, 'connect_device': <staticmethod(<function ClewareSwitch.connect_device>)>, 'EXE': None, 'DEFAULT_EXE_NAME': 'USBswitchCmd.exe', '_run_cmd': <staticmethod(<function ClewareSwitch._run_cmd>)>, '__repr__': <function ClewareSwitch.__repr__>, '__static_attributes__': ('exe', 'serial_number'), '__abstractmethods__': frozenset(), '_abc_impl': <_abc._abc_data object>, '_children': {}, '_manual_devices': []})#
__firstlineno__ = 8#
__init__(serial_number=None, usbswitchcmd_exe_path: str | None = None)[source]#
__module__ = 'devctrl.devices.switch.impl.cleware_switch'#
__repr__()[source]#
Returns:

The name of the device. If applicable, this should include serial port, GPIB address, etc.

__slots__ = ()#
__static_attributes__ = ('exe', 'serial_number')#
__weakref__#

list of weak references to the object

_abc_impl = <_abc._abc_data object>#
_children = {}#
_dummies_only = False#
static _enumerate_devices(usbswitchcmd_exe_path=None) list[str][source]#

This function should be overridden by device implementations only, and is not intended to be used directly. Instead, use list_devices() to get a list of devices. Use enumerate_devices only directly when you only want to list devices of one specific implementation, i.e., only SR830 Lock-In: SR830._enumerate_devices() :param class_name: The name of the device class

_manual_devices: list[str] = []#
static _run_cmd(cmd: list[str] | str, usbswitchcmd_exe_path=None) -> (<class 'int'>, <class 'str'>, <class 'str'>)[source]#

Run a USBswitchCmd.exe command. Run USBswitchCmd.exe -help in your terminal to get a list of commands. :param cmd: Command :param usbswitchcmd_exe_path: Path to the USBswitchCmd.exe executable :return: exit code, stdout, stderr

classmethod add_device(connect_info)#

Manually add a specific device. The device will show up when list_devices() is called for the device type. Call this from the device class implementation, e.g. use ModelXYZ9000.add_device(‘GPIB:1234:5678’) to add a specific device with a fixed GPIB address. This is useful when automatic discovery is undesired/impossible, either because it is not implemented or it disturbs other devices which can’t handle a identification request. :param cls: The device implementation class :param connect_info: A string argument that is passed to the connect() method of the device implementation, when the device is being connected.

static allow_only_dummy_devices()#
classmethod connect(device_type_name: str, device_name: str | None, **kwargs) Device#
Parameters:
  • device_type_name – The name of the device class

  • device_name – The name of the device class

static connect_device(device_name: str, usbswitchcmd_exe_path: str | None = None)[source]#
Parameters:

name – String with either “Device X” or “SerNum=X”. If both are present SerNum=X takes precedence.

Returns:

Device instance

classmethod connect_dummy(**kwargs) Device#

Connect an instance of the device’s dummy implementation

classmethod get_base_classes(recurse=True) dict[str, type[Device]]#

Return a flat dictionary of all base classes below this class :param recurse: If True, recursively search for base classes :return: dict of {class name: class}

classmethod get_device_name() str#
Returns:

The specific type name of the device, e.g., SR830 or Keithly2600

classmethod get_device_type_name() str#
Returns:

The general type name of the device, e.g., Lock-In Amplifier or Voltmeter

get_status() str#

Query the status of the device and return a string describing errors. If everything is ok, empty string must be returned :return: String of device status

is_connected() bool[source]#

Query whether the device is (still) connected

is_on() bool[source]#
classmethod list_devices() list[tuple[str, str]]#

Get a list of all devices for this type. The list made up of: - Manually added devices - Available devices (those returned by _enumerate_devices) - A dummy device (if a dummy implementation exists) - List of all devices of child classes

Returns:

list of available devices

off()[source]#
on()[source]#
run_cmd(cmd) -> (<class 'int'>, <class 'str'>, <class 'str'>)[source]#