diff --git a/ohmpi/hardware_components/mb_2023_0_X.py b/ohmpi/hardware_components/mb_2023_0_X.py index 4fe1c0b62d9a524b45d35f12d4849191ed997a4c..7055be06757cb000ee28eff998935268800fa28d 100644 --- a/ohmpi/hardware_components/mb_2023_0_X.py +++ b/ohmpi/hardware_components/mb_2023_0_X.py @@ -105,7 +105,7 @@ class Tx(TxAbstract): self.pin0.direction = Direction.OUTPUT self.pin1 = self.mcp_board.get_pin(1) self.pin1.direction = Direction.OUTPUT - self.polarity = 0 + #self.polarity = 0 self.gain = 2 / 3 if not subclass_init: self.exec_logger.event(f'{self.model}\ttx_init\tend\t{datetime.datetime.utcnow()}') diff --git a/ohmpi/hardware_components/mb_2024_0_2.py b/ohmpi/hardware_components/mb_2024_0_2.py index 2c756dfa048be11b37a0a522bf2ea8729cc953bb..deb8c5932dbd3412d3d4e2bdaa747f62bd3eb823 100644 --- a/ohmpi/hardware_components/mb_2024_0_2.py +++ b/ohmpi/hardware_components/mb_2024_0_2.py @@ -129,6 +129,33 @@ class Tx(Tx_mb_2023): self.exec_logger.debug(f'Switching DPS off') self._pwr_state = 'off' + @property + def polarity(self): + return self._polarity + + @Tx_mb_2023.polarity.setter + def polarity(self, polarity): + assert polarity in [-1, 0, 1] + self._polarity = polarity + if polarity == 1: + if not self.pwr.voltage_adjustable: + self.pwr_state = 'on' + self.pin0.value = True + self.pin1.value = False + time.sleep(self._activation_delay) + elif polarity == -1: + if not self.pwr.voltage_adjustable: + self.pwr_state = 'on' + self.pin0.value = False + self.pin1.value = True + time.sleep(self._activation_delay) + else: + if not self.pwr.voltage_adjustable: + self.pwr_state = 'off' + self.pin0.value = False + self.pin1.value = False + time.sleep(self._release_delay) + class Rx(Rx_mb_2023): def __init__(self, **kwargs): diff --git a/ohmpi/hardware_components/pwr_batt.py b/ohmpi/hardware_components/pwr_batt.py index dc67c8b88a742df803691446e0474d5f9c557e83..c66ad8e3572896daa6bc3f7c4f60bb020febef15 100644 --- a/ohmpi/hardware_components/pwr_batt.py +++ b/ohmpi/hardware_components/pwr_batt.py @@ -37,12 +37,6 @@ class Pwr(PwrAbstract): @current.setter def current(self, value, **kwargs): self.exec_logger.debug(f'Current cannot be set on {self.model}') - # - # def turn_off(self): - # self.exec_logger.debug(f'{self.model} cannot be turned off') - # - # def turn_on(self): - # self.exec_logger.debug(f'{self.model} is always on') @property def voltage(self): diff --git a/ohmpi/hardware_components/pwr_dps5005_fixed.py b/ohmpi/hardware_components/pwr_dps5005_fixed.py new file mode 100644 index 0000000000000000000000000000000000000000..0bdbe0724b4d9aae03c785742758ffee1c28220b --- /dev/null +++ b/ohmpi/hardware_components/pwr_dps5005_fixed.py @@ -0,0 +1,38 @@ +from ohmpi.hardware_components.abstract_hardware_components import PwrAbstract +import numpy as np +import datetime +import os +import time +from ohmpi.utils import enforce_specs +from minimalmodbus import Instrument # noqa +from ohmpi.hardware_components.pwr_batt import Pwr as Pwr_batt + +# hardware characteristics and limitations +SPECS = {'model': {'default': os.path.basename(__file__).rstrip('.py')}, + 'voltage': {'default': 12., 'max': 50., 'min': 0.}, + 'voltage_min': {'default': 0}, + 'voltage_max': {'default': 0}, + 'current_max': {'default': 60.}, + 'current_adjustable': {'default': False}, + 'voltage_adjustable': {'default': False}, + 'pwr_latency': {'default': .5} + } + + +class Pwr(Pwr_batt): + def __init__(self, **kwargs): + if 'model' not in kwargs.keys(): + for key in SPECS.keys(): + kwargs = enforce_specs(kwargs, SPECS, key) + subclass_init = False + else: + subclass_init = True + super().__init__(**kwargs) + if not subclass_init: + self.exec_logger.event(f'{self.model}\tpwr_init\tbegin\t{datetime.datetime.utcnow()}') + self._voltage = kwargs['voltage'] + self._current = np.nan + # self._state = 'on' + if not subclass_init: + self.exec_logger.event(f'{self.model}\tpwr_init\tend\t{datetime.datetime.utcnow()}') + diff --git a/ohmpi/hardware_system.py b/ohmpi/hardware_system.py index 634e3b8c9db80efd1df1958952ed860a2081a0a8..532026c3d626dc007cd5262e37c59a65fbcb12a8 100644 --- a/ohmpi/hardware_system.py +++ b/ohmpi/hardware_system.py @@ -137,6 +137,9 @@ class OhmPiHardware: if isinstance(self.tx, dict): self.tx = tx_module.Tx(**self.tx) self.tx.pwr = self.pwr + if not self.tx.pwr.voltage_adjustable: + self.tx._pwr_latency = 0 + self.tx.polarity = 0 self.tx.pwr._current_max = current_max # Initialize Muxes diff --git a/ohmpi/ohmpi.py b/ohmpi/ohmpi.py index 41e94e67ee0367ce5b6bd96b62e36590319d51e2..8e479a68ecafc01ca7ce3532df14da5208af7fd6 100644 --- a/ohmpi/ohmpi.py +++ b/ohmpi/ohmpi.py @@ -499,7 +499,7 @@ class OhmPi(object): """ # check pwr is on, if not, let's turn it on switch_power_off = False - if self._hw.pwr_state == 'off': + if self._hw.tx.pwr.voltage_adjustable and self._hw.pwr_state == 'off': self._hw.pwr_state = 'on' switch_power_off = True @@ -688,7 +688,8 @@ class OhmPi(object): fw_in_zip = self.settings['fw_in_zip'] # switch power on - self._hw.pwr_state = 'on' + if self._hw.tx.pwr.voltage_adjustable: + self._hw.pwr_state = 'on' self.status = 'running' self.exec_logger.debug(f'Status: {self.status}') self.exec_logger.debug(f'Measuring sequence: {self.sequence}')