diff --git a/ohmpi/hardware_components/abstract_hardware_components.py b/ohmpi/hardware_components/abstract_hardware_components.py index 22f2ea72aa71f9712c717e39bbce4a5263b69df1..b4de1fd7b0d8ac9a219dda41b1618ad6b38a1c6d 100644 --- a/ohmpi/hardware_components/abstract_hardware_components.py +++ b/ohmpi/hardware_components/abstract_hardware_components.py @@ -270,6 +270,7 @@ class TxAbstract(ABC): self._latency = kwargs.pop('latency', 0.) self.tx_sync = kwargs.pop('tx_sync', Event()) self.exec_logger.debug(f'{self.model} TX initialization') + self._pwr_state = 'off' @property def adc_gain(self): @@ -374,9 +375,18 @@ class TxAbstract(ABC): self.pwr.voltage = voltage self.exec_logger.debug(f'Voltage pulse of {polarity * self.pwr.voltage:.3f} V for {length:.3f} s') self.inject(polarity=polarity, injection_duration=length) + @property + @abstractmethod + def pwr_state(self): + return self._pwr_state - def switch_pwr(self): + @pwr_state.setter + def pwr_state(self, state): self.exec_logger.debug(f'Power source cannot be switched on or off on {self.model}') + if state == 'on': + self._pwr_state = 'on' + elif state == 'off': + self._pwr_state = 'off' class RxAbstract(ABC): def __init__(self, **kwargs): diff --git a/ohmpi/hardware_components/mb_2024_0_2.py b/ohmpi/hardware_components/mb_2024_0_2.py index 940f9c8485e6b01e6c1eaefe2d170eb115a65ef5..c4fda8cd622dd28511921d9d6ebb8e831d59d4d1 100644 --- a/ohmpi/hardware_components/mb_2024_0_2.py +++ b/ohmpi/hardware_components/mb_2024_0_2.py @@ -99,7 +99,13 @@ class Tx(Tx_mb_2023): Tx_mb_2023.inject(self, polarity=polarity, injection_duration=injection_duration) self.pin6.value = False - def switch_pwr(self,state='off', latency=4.): + @property + + def pwr_state(self): + return self._pwr_state + + @pwr_state.setter + def pwr_state(self, state, latency=4.): """Switches pwr on or off. Parameters @@ -111,11 +117,13 @@ class Tx(Tx_mb_2023): self.pin2.value = True self.pin3.value = True self.exec_logger.debug(f'Switching DPS on') + self._pwr_state = 'on' time.sleep(latency) # from pwr specs elif state == 'off': self.pin2.value = False self.pin3.value = False self.exec_logger.debug(f'Switching DPS off') + self._pwr_state = 'off' class Rx(Rx_mb_2023): diff --git a/ohmpi/hardware_system.py b/ohmpi/hardware_system.py index 1b1bdc6f9ab46765d8805a33c2c82aff15b73100..d828cb154a3728f1ca03334e97bbcdf4bf3577fd 100644 --- a/ohmpi/hardware_system.py +++ b/ohmpi/hardware_system.py @@ -430,6 +430,7 @@ class OhmPiHardware: self.tx.polarity = 0 #TODO: is this necessary? def _vab_pulses(self, vab, durations, sampling_rate, polarities=None, append=False): + switch_pwr_off = False n_pulses = len(durations) self.exec_logger.debug(f'n_pulses: {n_pulses}') if self.tx.pwr.voltage_adjustable: @@ -444,10 +445,14 @@ class OhmPiHardware: polarities = [-int(self.tx.polarity * np.heaviside(i % 2, -1.)) for i in range(n_pulses)] if not append: self._clear_values() + if self.tx.pwr_state == 'off': + self.tx.pwr_state('on') + switch_pwr_off = True for i in range(n_pulses): self._vab_pulse(vab=vab, duration=durations[i], sampling_rate=sampling_rate, polarity=polarities[i], append=True) - + if switch_pwr_off: + self.tx.pwr_state('off') def switch_mux(self, electrodes, roles=None, state='off', **kwargs): """Switches on multiplexer relays for given quadrupole.