diff --git a/hardware_components/abstract_hardware_components.py b/hardware_components/abstract_hardware_components.py index 07b3ef15c5ea0f15b6713f6efecd578097e5001c..df80282b8a84a19937407b5e46d855fdc5d0b728 100644 --- a/hardware_components/abstract_hardware_components.py +++ b/hardware_components/abstract_hardware_components.py @@ -87,6 +87,7 @@ class MuxAbstract(ABC): state : str, optional Either 'on' or 'off'. """ + status = True if elec_dict is not None: self.exec_logger.debug(f'Switching {self.board_name} ') # check to prevent A == B (SHORT-CIRCUIT) @@ -95,7 +96,8 @@ class MuxAbstract(ABC): if out.any() and state=='on': # noqa self.exec_logger.error('Trying to switch on some electrodes with both A and B roles. ' '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 # as to prevent burning the MN part which cannot take @@ -107,7 +109,8 @@ class MuxAbstract(ABC): 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. ' '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 self.exec_logger.debug(f'{self.board_id} waiting to switch.') @@ -117,12 +120,16 @@ class MuxAbstract(ABC): if elec > 0: # Is this condition related to electrodes to infinity? if (elec, role) in self.cabling.keys(): self.switch_one(elec, role, state) + status &= True else: self.exec_logger.warning(f'{self.board_id} skipping switching {(elec, role)} because it ' f'is not in board cabling.') + status = False self.exec_logger.debug(f'{self.board_id} switching done.') else: self.exec_logger.warning(f'Missing argument for {self.board_name}.switch: elec_dict is None.') + status = False + return status @abstractmethod def switch_one(self, elec=None, role=None, state=None): diff --git a/hardware_system.py b/hardware_system.py index b2125567d7e76031039a605a0f693bb5a80ead49..1a1bd47987450004c7a4dc18e4f8b6a21f24cd4c 100644 --- a/hardware_system.py +++ b/hardware_system.py @@ -302,11 +302,14 @@ class OhmPiHardware: mux_workers[idx] = Thread(target=self.mux_boards[mux].switch, kwargs={'elec_dict': elec_dict}) mux_workers[idx].start() self.mux_barrier.wait() + status = True for mux_worker in mux_workers: - mux_worker.join() + status &= mux_worker.join() else: self.exec_logger.error( 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): """Interactive method to test the multiplexer. diff --git a/ohmpi.py b/ohmpi.py index d8bfe8e9cd19d4b29ee33ebfc3df6c3e750d2d69..05b2837ac6b2fed6a3e85c66f6be49611be8f772 100644 --- a/ohmpi.py +++ b/ohmpi.py @@ -450,8 +450,11 @@ class OhmPi(object): injection_duration = self.settings['injection_duration'] tx_volt = float(tx_volt) - self.switch_mux_on(quad, cmd_id) - self._hw.vab_square_wave(tx_volt, cycle_length=injection_duration*2, cycles=nb_stack) + status = self.switch_mux_on(quad, cmd_id) + 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) d = { @@ -694,8 +697,8 @@ class OhmPi(object): 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) - if self.tx.voltage_adjustable: - voltage = self.tx.voltage # imposed voltage on dps + if self._hw.tx.voltage_adjustable: + voltage = self._hw.tx.voltage # imposed voltage on dps else: voltage = d['Vmn [mV]'] current = d['I [mA]'] @@ -769,7 +772,7 @@ class OhmPi(object): List of 4 integers representing the electrode numbers. """ 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): """Switches off multiplexer relays for given quadrupole. @@ -782,7 +785,7 @@ class OhmPi(object): List of 4 integers representing the electrode numbers. """ 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 """Interactive method to test the multiplexer boards.