diff --git a/ohmpi/hardware_components/abstract_hardware_components.py b/ohmpi/hardware_components/abstract_hardware_components.py index c670948c07e8102f66a7e066fab97f3cdecf2565..c6cd8b278035f0e3b6ea4171dfb0803198f4a814 100644 --- a/ohmpi/hardware_components/abstract_hardware_components.py +++ b/ohmpi/hardware_components/abstract_hardware_components.py @@ -51,6 +51,10 @@ class PwrAbstract(ABC): self._current_adjustable = kwargs.pop('current_adjustable', False) self._current = np.nan self._state = 'off' + self._current_min = kwargs.pop('current_min', 0.) + self._current_max = kwargs.pop('current_max', 0.) + self._current_min = kwargs.pop('voltage_min', 0.) + self._voltage_max = kwargs.pop('voltage_max', 0.) @property @abstractmethod @@ -63,6 +67,7 @@ class PwrAbstract(ABC): def current(self, value, **kwargs): # add actions to set the DPS current pass + @abstractmethod def turn_off(self): self.exec_logger.debug(f'Switching {self.board_name} off') @@ -86,6 +91,7 @@ class PwrAbstract(ABC): if not self.voltage_adjustable: self.exec_logger.warning(f'Voltage cannot be set on {self.board_name}...') else: + assert self._voltage_min < value < self._voltage_max # add actions to set the DPS voltage self._voltage = value @@ -211,6 +217,7 @@ class MuxAbstract(ABC): time.sleep(activation_time) self.exec_logger.debug('Test finished.') + class TxAbstract(ABC): def __init__(self, **kwargs): self.board_name = kwargs.pop('board_name', 'unknown TX hardware') @@ -266,6 +273,7 @@ class TxAbstract(ABC): @inj_time.setter def inj_time(self, value): assert isinstance(value, float) + assert value > 0. self._inj_time = value @property diff --git a/ohmpi/hardware_components/dummy_mux.py b/ohmpi/hardware_components/dummy_mux.py index 6b94dfc0b0fa150095b9c6c1a987b1c39977b572..21468e2dccbf7385f62afcbb923c5201db22653a 100644 --- a/ohmpi/hardware_components/dummy_mux.py +++ b/ohmpi/hardware_components/dummy_mux.py @@ -1,8 +1,9 @@ -from ohmpi.ohmpi.config import HARDWARE_CONFIG +from ohmpi.config import HARDWARE_CONFIG import os from ohmpi.hardware_components import MuxAbstract MUX_CONFIG = HARDWARE_CONFIG['mux'].pop('default', {}) + class Mux(MuxAbstract): def __init__(self, **kwargs): kwargs.update({'board_name': os.path.basename(__file__).rstrip('.py')}) diff --git a/ohmpi/hardware_components/mb_2024_rev_0_0.py b/ohmpi/hardware_components/mb_2024_rev_0_0.py index 4c1d7ca48083e706a2eb6f0f6b5e45c95a3d87e0..b9fcbdcad0bf858891d17af111b4012057e788ec 100644 --- a/ohmpi/hardware_components/mb_2024_rev_0_0.py +++ b/ohmpi/hardware_components/mb_2024_rev_0_0.py @@ -1,5 +1,5 @@ import importlib -from ohmpi.ohmpi.config import HARDWARE_CONFIG +from ohmpi.config import HARDWARE_CONFIG import adafruit_ads1x15.ads1115 as ads # noqa from adafruit_ads1x15.analog_in import AnalogIn # noqa from adafruit_mcp230xx.mcp23008 import MCP23008 # noqa diff --git a/ohmpi/hardware_components/pwr_batt.py b/ohmpi/hardware_components/pwr_batt.py index 36abf7697c1e81d030a39cf30c82357db334a90f..dd811385307fb63e0c3b01e4f3f2de8f790f0c5c 100644 --- a/ohmpi/hardware_components/pwr_batt.py +++ b/ohmpi/hardware_components/pwr_batt.py @@ -2,6 +2,7 @@ from ohmpi.hardware_components.abstract_hardware_components import PwrAbstract import numpy as np import os + class Pwr(PwrAbstract): def __init__(self, **kwargs): kwargs.update({'board_name': os.path.basename(__file__).rstrip('.py')}) @@ -11,7 +12,7 @@ class Pwr(PwrAbstract): self._voltage = voltage self._current_adjustable = False self._current = np.nan - + self._state = 'on' @property def current(self): diff --git a/ohmpi/hardware_system.py b/ohmpi/hardware_system.py index 5c3d1add4b9874f7f210419d72a863934ed57d26..30631dbf7a373fcdac560a75a887a9c61c9daf86 100644 --- a/ohmpi/hardware_system.py +++ b/ohmpi/hardware_system.py @@ -162,7 +162,7 @@ class OhmPiHardware: else: _readings = self.readings.tolist() sample = 0 - self.tx_sync.wait() + self.tx_sync.wait() # if not append or self._start_time is None: self._start_time = datetime.datetime.utcnow() while self.tx_sync.is_set(): @@ -171,7 +171,8 @@ class OhmPiHardware: self.rx.voltage]) sample += 1 sleep_time = self._start_time + datetime.timedelta(seconds=sample * sampling_rate / 1000) - lap - time.sleep(np.max([0.001, sleep_time.total_seconds()])) + time.sleep(np.max([0., sleep_time.total_seconds()])) # TODO set readings to nan if sleep time <0 and skip the sample (sample +=1) + self.exec_logger.warning(f'pulse {self._pulse}: elapsed time {(lap-self._start_time).total_seconds()} s') # TODO: Set to debug level self.readings = np.array(_readings) self._pulse += 1