64 lines
2.2 KiB
Python
64 lines
2.2 KiB
Python
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"],
|
|
}
|
|
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()
|
|
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 <type_name> in the dictionary returned by list_devices()
|
|
|
|
Returns
|
|
-------
|
|
An LedControlDevice object
|
|
"""
|
|
if type_name == TYPENAME_TEST:
|
|
return TestLedControlDevice()
|
|
elif type_name == TYPENAME_LEDD1B:
|
|
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}") |