Commit bf4509ee authored by Arnaud WATLET's avatar Arnaud WATLET
Browse files

Adds pwr_state on off in gian_auto

Showing with 17 additions and 9 deletions
+17 -9
......@@ -14,7 +14,7 @@ SPECS = {'model': {'default': os.path.basename(__file__).rstrip('.py')},
'current_max': {'default': 100.},
'current_adjustable': {'default': False},
'voltage_adjustable': {'default': True},
'pwr_latency':{'default': .3}
'pwr_latency': {'default': .3}
}
# TODO: Complete this code... handle modbus connection
......@@ -80,6 +80,7 @@ class Pwr(PwrAbstract):
def current_max(self, value):
self.connection.write_register(0x0001, value * 10, 0)
@property
def pwr_state(self):
return self._pwr_state
......
......@@ -173,9 +173,14 @@ class OhmPiHardware:
self._start_time = None
self._pulse = 0
def _gain_auto(self, polarities=(1, -1)): # TODO: improve _gain_auto
def _gain_auto(self, polarities=(1, -1), vab=5., switch_pwr_off=False) # TODO: improve _gain_auto
self.exec_logger.event(f'OhmPiHardware\ttx_rx_gain_auto\tbegin\t{datetime.datetime.utcnow()}')
current, voltage = 0., 0.
if self.tx.pwr.voltage_adjustable:
self.tx.pwr.voltage = vab
if self.tx.pwr.pwr_state == 'off':
self.tx.pwr.pwr_state = 'on'
switch_pwr_off = True
tx_gains = []
rx_gains = []
for pol in polarities:
......@@ -202,6 +207,8 @@ class OhmPiHardware:
self.tx.gain = min(tx_gains)
self.rx.gain = min(rx_gains)
# self.rx.gain_auto(voltage)
if switch_pwr_off:
self.tx.pwr.pwr_state = 'off'
self.exec_logger.event(f'OhmPiHardware\ttx_rx_gain_auto\tend\t{datetime.datetime.utcnow()}')
def _inject(self, polarity=1, injection_duration=None): # TODO: deal with voltage or current pulse
......@@ -416,10 +423,10 @@ class OhmPiHardware:
if self.tx.pwr_state == 'off':
self.tx.pwr_state = 'on'
switch_tx_pwr_off = True
if self.tx.pwr.pwr_state == 'off':
self.tx.pwr.pwr_state = 'on'
switch_pwr_off = True
self._gain_auto()
# if self.tx.pwr.pwr_state == 'off':
# self.tx.pwr.pwr_state = 'on'
# switch_pwr_off = True
self._gain_auto(vab=vab)
assert 0. <= duty_cycle <= 1.
if duty_cycle < 1.:
durations = [cycle_duration/2 * duty_cycle, cycle_duration/2 * (1.-duty_cycle)] * 2 * cycles
......@@ -462,15 +469,15 @@ class OhmPiHardware:
if self.tx.pwr_state == 'off':
self.tx.pwr_state = 'on'
switch_pwr_off = True
if self.tx.pwr.pwr_state == 'off':
self.tx.pwr.pwr_state = 'on'
switch_pwr_off = True
n_pulses = len(durations)
self.exec_logger.debug(f'n_pulses: {n_pulses}')
if self.tx.pwr.voltage_adjustable:
self.tx.pwr.voltage = vab
else:
vab = self.tx.pwr.voltage
if self.tx.pwr.pwr_state == 'off':
self.tx.pwr.pwr_state = 'on'
switch_pwr_off = True
if sampling_rate is None:
sampling_rate = RX_CONFIG['sampling_rate']
if polarities is not None:
......
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