From e5f68e477a52e39c2013b20b34bc1276a7ca4cfa Mon Sep 17 00:00:00 2001 From: Ollie Copping Date: Thu, 2 May 2024 10:23:22 +0100 Subject: [PATCH] HV Reset (#14) * Add hv_reset function along with 'high_voltage/state' status variable Edited logging in hv_reset() Removed unused state get Formatting * Remove iterator variable as unused Co-authored-by: Gary Yendell * Change to sensor material check and counter limit reached * Rework hv_reset function to run in a thread; Expose command to API * Formatting * Fixed HV reset iteration logic * Increased time sleep at end of iteration --------- Co-authored-by: Gary Yendell --- .../eiger_detector/control/eiger_detector.py | 59 ++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/python/src/eiger_detector/control/eiger_detector.py b/python/src/eiger_detector/control/eiger_detector.py index 2cac25e..9e049a6 100644 --- a/python/src/eiger_detector/control/eiger_detector.py +++ b/python/src/eiger_detector/control/eiger_detector.py @@ -82,7 +82,8 @@ class EigerDetector(object): 'link_0', 'link_1', 'link_2', - 'link_3' + 'link_3', + 'high_voltage/state' ] DETECTOR_BOARD_STATUS = [ 'th0_temp', @@ -126,6 +127,7 @@ def __init__(self, endpoint, api_version): self._connected = False self._sequence_id = 0 self._initializing = False + self._hv_resetting = False self._error = '' self._acquisition_complete = True self._armed = False @@ -142,6 +144,7 @@ def __init__(self, endpoint, api_version): self._trigger_event = threading.Event() self._acquisition_event = threading.Event() self._initialize_event = threading.Event() + self._hv_resetting_event = threading.Event() self._detector_config_uri = '{}/{}/{}/{}'.format(self.STR_DETECTOR, self.STR_API, api_version, self.STR_CONFIG) self._detector_status_uri = '{}/{}/{}/{}'.format(self.STR_DETECTOR, self.STR_API, api_version, self.STR_STATUS) @@ -388,6 +391,10 @@ def __init__(self, endpoint, api_version): self._status_thread = threading.Thread(target=self.do_check_status) self._status_thread.start() + # Run the hv resetting thread + self._hv_reset_thread = threading.Thread(target=self.do_hv_reset) + self._hv_reset_thread.start() + def read_all_config(self): for cfg in self.DETECTOR_CONFIG: param = self.read_detector_config(cfg) @@ -414,6 +421,8 @@ def get(self, path): return {'send_trigger': {'value': 0}} elif path == 'command/initialize': return {'initialize': {'value': self._initializing}} + elif path == 'command/hv_reset': + return {'hv_reset': {'value': self._hv_resetting}} else: return self._params.get(path, with_metadata=True) @@ -427,6 +436,8 @@ def set(self, path, value): return self.send_trigger() elif path == 'command/initialize': return self.initialize_detector() + elif path == 'command/hv_reset': + return self.hv_reset_detector() else: # mbbi record will send integers; change to string if any(option == path.split("/")[-1] for option in option_config_items): @@ -684,6 +695,11 @@ def initialize_detector(self): logging.info("Initializing the detector") self._initialize_event.set() + def hv_reset_detector(self): + self._hv_resetting = True + logging.info("HV Resetting the detector") + self._hv_resetting_event.set() + def fetch_stale_parameters(self, blocking=False): with self._lock: # Take a copy in case it is changed while we fetch @@ -836,6 +852,13 @@ def do_check_status(self): pass time.sleep(.5) + def do_hv_reset(self): + while self._executing: + if self._hv_resetting_event.wait(1.0): + self.hv_reset() + self._hv_resetting = False + self._hv_resetting_event.clear() + def stop_acquisition(self): # Perform an abort sequence logging.info("Stop acquisition called") @@ -854,6 +877,40 @@ def lv_loop(self): self.read_detector_live_image() time.sleep(0.1) + def _get_hv_state(self) -> str: + hv_state = getattr(self, "high_voltage/state")["value"] + + return hv_state + + def hv_reset(self): + logging.info("Initiating HV Reset") + + material = getattr(self, "sensor_material")["value"] + # Make sure sensor material is CdTe + if material.lower() != "cdte": + logging.error("Sensor material is not CdTe.") + return + + # send HV reset command, 45 seconds is recommended, in a loop of 10 + niterations = 10 + for i in range(niterations): + counter = 0 + while self._get_hv_state() != "READY": + counter += 1 + if counter > 60: + logging.error( + "Detector failed to be ready after 600 seconds, " + "Stopping hv reset" + ) + return + time.sleep(10) + logging.info(f"Starting HV Reset iteration {i}") + self.write_detector_command("hv_reset", 45) + # Need to wait for command to be processed + time.sleep(60) + + logging.info("HV Reset complete") + def shutdown(self): self._executing = False