Skip to content

Commit

Permalink
HV Reset (#14)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* 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 <[email protected]>
  • Loading branch information
OCopping and GDYendell authored May 2, 2024
1 parent 79af776 commit e5f68e4
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion python/src/eiger_detector/control/eiger_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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

Expand Down

0 comments on commit e5f68e4

Please sign in to comment.