diff --git a/cpdctrl/led_control_device/__init__.py b/cpdctrl/led_control_device/__init__.py index e7d07bf..68c04d9 100644 --- a/cpdctrl/led_control_device/__init__.py +++ b/cpdctrl/led_control_device/__init__.py @@ -1,64 +1,25 @@ from cpdctrl.led_control_device.base import LedControlDevice from cpdctrl.led_control_device.impl.test import TestLedControlDevice -# can not use a static class member as name since the import might fail -TYPENAME_DC2200 = "Thorlabs DC2200" -TYPENAME_LEDD1B = "Thorlabs LEDD1B" -TYPENAME_TEST = "Test" def list_devices() -> dict[str,list[str]]: - """ - Get a list of all devices that are available to connect - The returned device names may be passed to connect_device() to connect the device and acquire the handle - - If a module is not installed, it will not be listed. - - Returns - ------- - dict[str,list[str]] - A dictionary with keys being the typename and values being a list of device names - """ devices = { - TYPENAME_TEST: ["Led Control Dummy Device"], + "TEST": ["Led Control Dummy Device"], } try: from .impl import thorlabs_ledd1b as th - devices[TYPENAME_LEDD1B] = ["Thorlabs LEDD1B"] #keithley2700.enumerate_devices() - except ImportError: - pass - try: - from .impl.thorlabs_dc2200 import DC2200 - devices[TYPENAME_DC2200] = DC2200.enumerate_devices() + devices["ARDUINO"] = ["Thorlabs LEDD1B"] #keithley2700.enumerate_devices() except ImportError: pass return devices -def connect_device(type_name: str, device_name: str) -> LedControlDevice: - """ - Connect to a device - Parameters - ---------- - type_name - Type of the device, first key of the dictionary returned by list_devices() - device_name - Name of the device, element of the list belonging to in the dictionary returned by list_devices() - - Returns - ------- - An LedControlDevice object - """ - if type_name == TYPENAME_TEST: +def connect_device(typename: str, devicename: str) -> LedControlDevice: + if typename == "TEST": return TestLedControlDevice() - elif type_name == TYPENAME_LEDD1B: + elif typename == "ARDUINO": try: from .impl import thorlabs_ledd1b as th return th.LEDD1B() except ImportError as e: raise ValueError(f"Arduino devices not available: {e}") - elif type_name == TYPENAME_DC2200: - try: - from .impl.thorlabs_dc2200 import DC2200 - return DC2200.connect_device(device_name) - except ImportError as e: - raise ValueError(f"DC2200 devices not available: {e}") - raise ValueError(f"Unknown device type {type_name}") \ No newline at end of file + raise ValueError(f"Unknown device type {typename}") \ No newline at end of file diff --git a/cpdctrl/led_control_device/impl/thorlabs_dc2200.py b/cpdctrl/led_control_device/impl/thorlabs_dc2200.py deleted file mode 100644 index 93c8054..0000000 --- a/cpdctrl/led_control_device/impl/thorlabs_dc2200.py +++ /dev/null @@ -1,63 +0,0 @@ -from ..base import LedControlDevice - -import logging -log = logging.getLogger(__name__) - -import pyvisa - -class DC2200(LedControlDevice): - """ - Class for controlling Thorlabs DC2200 LED controller. - This works only when the LED is connected to Terminal 2 - Args: - instr (pyvisa.Resource): pyvisa resource object for the LED controller. - """ - def __init__(self, instr: pyvisa.Resource): - super().__init__() - self.instr = instr - # Led name, format: - # ",, < led_head_serial_no_string >, < fw_version_major_num >, < fw_version_minor_num >, < fw_version_subminor_num > " - self.name = instr.query('SYSTem:TERMinal2:HTYPe?') - # led presence test - self.instr.write('OUTPut[1]:TERMinal2:TEST:INITiate') - # constant brightness - self.instr.write('SOURCE1:MODE CB') - # turn off - self.instr.write(f'SOURCE1:CBRightness:BRIGhtness 0') - self.instr.write('OUTPUT1:STATE ON') - - def on(self): - self.instr.write(f'SOURCE1:CBRightness:BRIGhtness 100') - - def off(self): - self.instr.write(f'SOURCE1:CBRightness:BRIGhtness 0') - - def set_level(self, level:int): - self.instr.write(f'SOURCE1:CBRightness:BRIGhtness {level}') - - @staticmethod - def enumerate_devices(query="(GPIB)|(USB)?*::INSTR"): - rm = pyvisa.ResourceManager() - res = [] - for r in rm.list_resources(query): - try: - instr = rm.open_resource(r) - name = instr.query('*IDN?') - if 'DC2200' in name: - res.append(r) - instr.close() - except: - log.debug(f"Could not open Visa resources {r}") - return res - - @staticmethod - def connect_device(name): - rm = pyvisa.ResourceManager() - instr = rm.open_resource(name) - return DC2200(instr) - - - - - -