Add enumeration and test devices

This commit is contained in:
CPD 2025-02-25 12:10:36 +01:00
parent 91da580591
commit a66f014ce2
4 changed files with 124 additions and 1 deletions

View File

@ -1 +1,25 @@
from cpdctrl.led_control_device.base import LedControlDevice
from cpdctrl.led_control_device.base import LedControlDevice
from cpdctrl.led_control_device.impl.test import TestLedControlDevice
def list_devices() -> dict[str,list[str]]:
devices = {
"TEST": ["Led Control Dummy Device"],
}
try:
from .impl import thorlabs_ledd1b as th
devices["ARDUINO"] = ["Thorlabs LEDD1B"] #keithley2700.enumerate_devices()
except ImportError:
pass
return devices
def connect_device(typename: str, devicename: str) -> LedControlDevice:
if typename == "TEST":
return TestLedControlDevice()
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}")
raise ValueError(f"Unknown device type {typename}")

View File

@ -0,0 +1,14 @@
from ..base import LedControlDevice
class TestLedControlDevice(LedControlDevice):
def __init__(self):
super().__init__()
def on(self):
pass
def off(self):
pass
def set_level(level: int):
pass

View File

@ -0,0 +1,31 @@
from .base import VoltageMeasurementDevice
try:
from .impl.keithley2700 import Keithley2700
except ImportError:
pass
from .impl.test import TestVoltageMeasurementDevice
def list_devices() -> dict[str,list[str]]:
devices = {
"TEST": ["Voltage Measurement Dummy Device"],
}
try:
from .impl import keithley2700
devices["VISA"] = ["example visa device"] #keithley2700.enumerate_devices()
except ImportError:
pass
return devices
def connect_device(typename: str, devicename: str) -> VoltageMeasurementDevice:
if typename == "TEST":
return TestVoltageMeasurementDevice()
elif typename == "VISA":
try:
from .impl import keithley2700
return keithley2700.init(devicename)
except ImportError as e:
raise ValueError(f"VISA devices not available: {e}")
raise ValueError(f"Unknown device type {typename}")

View File

@ -0,0 +1,54 @@
from ..base import VoltageMeasurementDevice
from typing import Callable
from time import time as now
import numpy as np
class TestVoltageMeasurementDevice(VoltageMeasurementDevice):
def __init__(self, ampltiude: float=1.0, frequency: float=3.0):
super().__init__()
self.amplitude = ampltiude
self.frequency = frequency
self.t0 = now()
# RUN COMMANDS ON THE DEVICE
def run(self, code, verbose=False):
pass
def run_script(self, script_path, verbose=False):
pass
def reset(self, verbose=False):
pass
def read_value(self) -> tuple[float, float]:
"""
Read a single value
Returns
-------
[timestamp, voltage]
"""
t = now() - self.t0
v = self.amplitude * np.sin(2 * np.pi * t / self.frequency)
return t, v
def measure(self, interval: int, update_func: Callable[None, [int, float, float]] | None = None,
max_measurements: int | None = None):
"""
Take voltage readings after <interval> milliseconds.
Parameters
----------
interval : int
Number of milliseconds to wait between readings.
update_func : Callable[None, [int, float, float]] or None, optional
A function that is called after each reading with parameters <n_reading>, <time>, <voltage>. The default is None.
max_measurements : int or None, optional
Number of readings to perform. Set to None for infinite. The default is None.
Returns
-------
None.
"""
pass