Commit 595dbb5e authored by Olivier Kaufmann's avatar Olivier Kaufmann
Browse files

Tries to handle BrokenBarrier Exception

Showing with 26 additions and 18 deletions
+26 -18
......@@ -3,7 +3,7 @@ from abc import ABC, abstractmethod
import numpy as np
from ohmpi.logging_setup import create_stdout_logger
import time
from threading import Barrier
from threading import Barrier, BrokenBarrierError
class CtlAbstract(ABC):
......@@ -168,31 +168,38 @@ class MuxAbstract(ABC):
# as to prevent burning the MN part which cannot take
# the full voltage of the DPS
if 'A' in elec_dict.keys() and 'B' in elec_dict.keys() and 'M' in elec_dict.keys() and 'N' in elec_dict.keys():
if not bypass_check and (np.in1d(elec_dict['M'], elec_dict['A']).any() # noqa
if bypass_check:
self.exec_logger.debug('Bypassing switching check')
elif (np.in1d(elec_dict['M'], elec_dict['A']).any() # noqa
or np.in1d(elec_dict['M'], elec_dict['B']).any() # noqa
or np.in1d(elec_dict['N'], elec_dict['A']).any() # 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. '
'This could create an over-voltage in the RX! Switching aborted.')
self.barrier.abort()
status = False
return status
elif bypass_check:
self.exec_logger.debug('Bypassing switching check')
elif bypass_check:
self.exec_logger.debug('Bypassing switching check')
# 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.barrier.wait()
for role in elec_dict:
for elec in elec_dict[role]:
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.debug(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.')
try:
self.barrier.wait()
for role in elec_dict:
for elec in elec_dict[role]:
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.debug(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.')
except BrokenBarrierError:
self.exec_logger.debug(f'Barrier error {self.board_id} switching aborted.')
status = False
else:
self.exec_logger.warning(f'Missing argument for {self.board_name}.switch: elec_dict is None.')
status = False
......
......@@ -767,8 +767,9 @@ class OhmPi(object):
Bypasses checks for A==M or A==M or B==M or B==N (i.e. used for rs-check)
"""
assert len(quadrupole) == 4
if self._hw.tx.pwr.voltage > self._hw.rx._voltage_max and bypass_check:
self.exec_logger.warning('Cannot bypass checking electrode roles because tx voltage is over rx maximum voltage')
if (self._hw.tx.pwr.voltage > self._hw.rx._voltage_max) and bypass_check:
self.exec_logger.warning('Cannot bypass checking electrode roles because tx pwr voltage is over rx maximum voltage')
self.exec_logger.debug(f'tx pwr voltage: {self._hw.tx.pwr.voltage}, rx max voltage: {self._hw.rx._voltage_max}')
return False
else:
return self._hw.switch_mux(electrodes=quadrupole, state='on', bypass_check=bypass_check)
......
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