Commit c5c70c6b authored by Olivier Kaufmann's avatar Olivier Kaufmann
Browse files

Improves switching -> return a status

Showing with 22 additions and 9 deletions
+22 -9
...@@ -87,6 +87,7 @@ class MuxAbstract(ABC): ...@@ -87,6 +87,7 @@ class MuxAbstract(ABC):
state : str, optional state : str, optional
Either 'on' or 'off'. Either 'on' or 'off'.
""" """
status = True
if elec_dict is not None: if elec_dict is not None:
self.exec_logger.debug(f'Switching {self.board_name} ') self.exec_logger.debug(f'Switching {self.board_name} ')
# check to prevent A == B (SHORT-CIRCUIT) # check to prevent A == B (SHORT-CIRCUIT)
...@@ -95,7 +96,8 @@ class MuxAbstract(ABC): ...@@ -95,7 +96,8 @@ class MuxAbstract(ABC):
if out.any() and state=='on': # noqa if out.any() and state=='on': # noqa
self.exec_logger.error('Trying to switch on some electrodes with both A and B roles. ' self.exec_logger.error('Trying to switch on some electrodes with both A and B roles. '
'This would create a short-circuit! Switching aborted.') 'This would create a short-circuit! Switching aborted.')
return status = False
return status
# check that none of M or N are the same as A or B # check that none of M or N are the same as A or B
# as to prevent burning the MN part which cannot take # as to prevent burning the MN part which cannot take
...@@ -107,7 +109,8 @@ class MuxAbstract(ABC): ...@@ -107,7 +109,8 @@ class MuxAbstract(ABC):
or np.in1d(elec_dict['N'], elec_dict['B']).any()) and state=='on': # noqa or np.in1d(elec_dict['N'], elec_dict['B']).any()) and state=='on': # noqa
self.exec_logger.error('Trying to switch on some electrodes with both M or N role and A or B role. ' self.exec_logger.error('Trying to switch on some electrodes with both M or N role and A or B role. '
'This could create an over-voltage in the RX! Switching aborted.') 'This could create an over-voltage in the RX! Switching aborted.')
return status = False
return status
# if all ok, then wait for the barrier to open, then switch the electrodes # if all ok, then wait for the barrier to open, then switch the electrodes
self.exec_logger.debug(f'{self.board_id} waiting to switch.') self.exec_logger.debug(f'{self.board_id} waiting to switch.')
...@@ -117,12 +120,16 @@ class MuxAbstract(ABC): ...@@ -117,12 +120,16 @@ class MuxAbstract(ABC):
if elec > 0: # Is this condition related to electrodes to infinity? if elec > 0: # Is this condition related to electrodes to infinity?
if (elec, role) in self.cabling.keys(): if (elec, role) in self.cabling.keys():
self.switch_one(elec, role, state) self.switch_one(elec, role, state)
status &= True
else: else:
self.exec_logger.warning(f'{self.board_id} skipping switching {(elec, role)} because it ' self.exec_logger.warning(f'{self.board_id} skipping switching {(elec, role)} because it '
f'is not in board cabling.') f'is not in board cabling.')
status = False
self.exec_logger.debug(f'{self.board_id} switching done.') self.exec_logger.debug(f'{self.board_id} switching done.')
else: else:
self.exec_logger.warning(f'Missing argument for {self.board_name}.switch: elec_dict is None.') self.exec_logger.warning(f'Missing argument for {self.board_name}.switch: elec_dict is None.')
status = False
return status
@abstractmethod @abstractmethod
def switch_one(self, elec=None, role=None, state=None): def switch_one(self, elec=None, role=None, state=None):
......
...@@ -302,11 +302,14 @@ class OhmPiHardware: ...@@ -302,11 +302,14 @@ class OhmPiHardware:
mux_workers[idx] = Thread(target=self.mux_boards[mux].switch, kwargs={'elec_dict': elec_dict}) mux_workers[idx] = Thread(target=self.mux_boards[mux].switch, kwargs={'elec_dict': elec_dict})
mux_workers[idx].start() mux_workers[idx].start()
self.mux_barrier.wait() self.mux_barrier.wait()
status = True
for mux_worker in mux_workers: for mux_worker in mux_workers:
mux_worker.join() status &= mux_worker.join()
else: else:
self.exec_logger.error( self.exec_logger.error(
f'Unable to switch {state} electrodes: number of electrodes and number of roles do not match!') f'Unable to switch {state} electrodes: number of electrodes and number of roles do not match!')
status = False
return status
def test_mux(self, channel=None, activation_time=1.0): def test_mux(self, channel=None, activation_time=1.0):
"""Interactive method to test the multiplexer. """Interactive method to test the multiplexer.
......
...@@ -450,8 +450,11 @@ class OhmPi(object): ...@@ -450,8 +450,11 @@ class OhmPi(object):
injection_duration = self.settings['injection_duration'] injection_duration = self.settings['injection_duration']
tx_volt = float(tx_volt) tx_volt = float(tx_volt)
self.switch_mux_on(quad, cmd_id) status = self.switch_mux_on(quad, cmd_id)
self._hw.vab_square_wave(tx_volt, cycle_length=injection_duration*2, cycles=nb_stack) if status:
self._hw.vab_square_wave(tx_volt, cycle_length=injection_duration*2, cycles=nb_stack)
else:
self.exec_logger.info('Skipping {quad}')
self.switch_mux_off(quad, cmd_id) self.switch_mux_off(quad, cmd_id)
d = { d = {
...@@ -694,8 +697,8 @@ class OhmPi(object): ...@@ -694,8 +697,8 @@ class OhmPi(object):
self.switch_mux_on(quad) # put before raising the pins (otherwise conflict i2c) self.switch_mux_on(quad) # put before raising the pins (otherwise conflict i2c)
d = self.run_measurement(quad=quad, nb_stack=1, injection_duration=0.2, tx_volt=tx_volt, autogain=False) d = self.run_measurement(quad=quad, nb_stack=1, injection_duration=0.2, tx_volt=tx_volt, autogain=False)
if self.tx.voltage_adjustable: if self._hw.tx.voltage_adjustable:
voltage = self.tx.voltage # imposed voltage on dps voltage = self._hw.tx.voltage # imposed voltage on dps
else: else:
voltage = d['Vmn [mV]'] voltage = d['Vmn [mV]']
current = d['I [mA]'] current = d['I [mA]']
...@@ -769,7 +772,7 @@ class OhmPi(object): ...@@ -769,7 +772,7 @@ class OhmPi(object):
List of 4 integers representing the electrode numbers. List of 4 integers representing the electrode numbers.
""" """
assert len(quadrupole) == 4 assert len(quadrupole) == 4
self._hw.switch_mux(electrodes=quadrupole, state='on') return self._hw.switch_mux(electrodes=quadrupole, state='on')
def switch_mux_off(self, quadrupole, cmd_id=None): def switch_mux_off(self, quadrupole, cmd_id=None):
"""Switches off multiplexer relays for given quadrupole. """Switches off multiplexer relays for given quadrupole.
...@@ -782,7 +785,7 @@ class OhmPi(object): ...@@ -782,7 +785,7 @@ class OhmPi(object):
List of 4 integers representing the electrode numbers. List of 4 integers representing the electrode numbers.
""" """
assert len(quadrupole) == 4 assert len(quadrupole) == 4
self._hw.switch_mux(electrodes=quadrupole, state='off') return self._hw.switch_mux(electrodes=quadrupole, state='off')
def test_mux(self, activation_time=1.0, mux_id=None, cmd_id=None): # TODO: add this in the MUX code def test_mux(self, activation_time=1.0, mux_id=None, cmd_id=None): # TODO: add this in the MUX code
"""Interactive method to test the multiplexer boards. """Interactive method to test the multiplexer boards.
......
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