Commit 103593b4 authored by Arnaud WATLET's avatar Arnaud WATLET
Browse files

Adds pwr_state on tx to switch dps on and off

Showing with 26 additions and 3 deletions
+26 -3
...@@ -270,6 +270,7 @@ class TxAbstract(ABC): ...@@ -270,6 +270,7 @@ class TxAbstract(ABC):
self._latency = kwargs.pop('latency', 0.) self._latency = kwargs.pop('latency', 0.)
self.tx_sync = kwargs.pop('tx_sync', Event()) self.tx_sync = kwargs.pop('tx_sync', Event())
self.exec_logger.debug(f'{self.model} TX initialization') self.exec_logger.debug(f'{self.model} TX initialization')
self._pwr_state = 'off'
@property @property
def adc_gain(self): def adc_gain(self):
...@@ -374,9 +375,18 @@ class TxAbstract(ABC): ...@@ -374,9 +375,18 @@ class TxAbstract(ABC):
self.pwr.voltage = voltage self.pwr.voltage = voltage
self.exec_logger.debug(f'Voltage pulse of {polarity * self.pwr.voltage:.3f} V for {length:.3f} s') 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) 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}') 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): class RxAbstract(ABC):
def __init__(self, **kwargs): def __init__(self, **kwargs):
......
...@@ -99,7 +99,13 @@ class Tx(Tx_mb_2023): ...@@ -99,7 +99,13 @@ class Tx(Tx_mb_2023):
Tx_mb_2023.inject(self, polarity=polarity, injection_duration=injection_duration) Tx_mb_2023.inject(self, polarity=polarity, injection_duration=injection_duration)
self.pin6.value = False 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. """Switches pwr on or off.
Parameters Parameters
...@@ -111,11 +117,13 @@ class Tx(Tx_mb_2023): ...@@ -111,11 +117,13 @@ class Tx(Tx_mb_2023):
self.pin2.value = True self.pin2.value = True
self.pin3.value = True self.pin3.value = True
self.exec_logger.debug(f'Switching DPS on') self.exec_logger.debug(f'Switching DPS on')
self._pwr_state = 'on'
time.sleep(latency) # from pwr specs time.sleep(latency) # from pwr specs
elif state == 'off': elif state == 'off':
self.pin2.value = False self.pin2.value = False
self.pin3.value = False self.pin3.value = False
self.exec_logger.debug(f'Switching DPS off') self.exec_logger.debug(f'Switching DPS off')
self._pwr_state = 'off'
class Rx(Rx_mb_2023): class Rx(Rx_mb_2023):
......
...@@ -430,6 +430,7 @@ class OhmPiHardware: ...@@ -430,6 +430,7 @@ class OhmPiHardware:
self.tx.polarity = 0 #TODO: is this necessary? self.tx.polarity = 0 #TODO: is this necessary?
def _vab_pulses(self, vab, durations, sampling_rate, polarities=None, append=False): def _vab_pulses(self, vab, durations, sampling_rate, polarities=None, append=False):
switch_pwr_off = False
n_pulses = len(durations) n_pulses = len(durations)
self.exec_logger.debug(f'n_pulses: {n_pulses}') self.exec_logger.debug(f'n_pulses: {n_pulses}')
if self.tx.pwr.voltage_adjustable: if self.tx.pwr.voltage_adjustable:
...@@ -444,10 +445,14 @@ class OhmPiHardware: ...@@ -444,10 +445,14 @@ class OhmPiHardware:
polarities = [-int(self.tx.polarity * np.heaviside(i % 2, -1.)) for i in range(n_pulses)] polarities = [-int(self.tx.polarity * np.heaviside(i % 2, -1.)) for i in range(n_pulses)]
if not append: if not append:
self._clear_values() self._clear_values()
if self.tx.pwr_state == 'off':
self.tx.pwr_state('on')
switch_pwr_off = True
for i in range(n_pulses): for i in range(n_pulses):
self._vab_pulse(vab=vab, duration=durations[i], sampling_rate=sampling_rate, polarity=polarities[i], self._vab_pulse(vab=vab, duration=durations[i], sampling_rate=sampling_rate, polarity=polarities[i],
append=True) append=True)
if switch_pwr_off:
self.tx.pwr_state('off')
def switch_mux(self, electrodes, roles=None, state='off', **kwargs): def switch_mux(self, electrodes, roles=None, state='off', **kwargs):
"""Switches on multiplexer relays for given quadrupole. """Switches on multiplexer relays for given quadrupole.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment