wip remove live mode fornow still
This commit is contained in:
@@ -178,13 +178,13 @@ class Pilatus(PSIDeviceBase, ADBase):
|
|||||||
)
|
)
|
||||||
self._poll_thread_kill_event = threading.Event()
|
self._poll_thread_kill_event = threading.Event()
|
||||||
self._poll_rate = 1 # Poll rate in Hz
|
self._poll_rate = 1 # Poll rate in Hz
|
||||||
self._live_mode_thread = threading.Thread(
|
# self._live_mode_thread = threading.Thread(
|
||||||
target=self._live_mode_loop, daemon=True, name=f"{self.name}_live_mode_thread"
|
# target=self._live_mode_loop, daemon=True, name=f"{self.name}_live_mode_thread"
|
||||||
)
|
# )
|
||||||
self._live_mode_kill_event = threading.Event()
|
# self._live_mode_kill_event = threading.Event()
|
||||||
self._live_mode_run_event = threading.Event()
|
# self._live_mode_run_event = threading.Event()
|
||||||
self._live_mode_stopped_event = threading.Event()
|
# self._live_mode_stopped_event = threading.Event()
|
||||||
self._live_mode_stopped_event.set() # Initial state is stopped
|
# self._live_mode_stopped_event.set() # Initial state is stopped
|
||||||
|
|
||||||
########################################
|
########################################
|
||||||
# Custom Beamline Methods #
|
# Custom Beamline Methods #
|
||||||
@@ -219,79 +219,89 @@ class Pilatus(PSIDeviceBase, ADBase):
|
|||||||
f"Error while polling array data for preview of {self.name}: {content}"
|
f"Error while polling array data for preview of {self.name}: {content}"
|
||||||
)
|
)
|
||||||
|
|
||||||
def start_live_mode(self, exp_time: float, n_images_max: int = 50000):
|
# def start_live_mode(self, exp_time: float, n_images_max: int = 50000):
|
||||||
"""
|
# """
|
||||||
Start live mode with given exposure time.
|
# Start live mode with given exposure time.
|
||||||
|
|
||||||
Args:
|
# Args:
|
||||||
exp_time (float) : Exposure time in seconds
|
# exp_time (float) : Exposure time in seconds
|
||||||
n_images_max (int): Maximum number of images to capture during live mode.
|
# n_images_max (int): Maximum number of images to capture during live mode.
|
||||||
Default is 5000. Only reset if needed.
|
# Default is 5000. Only reset if needed.
|
||||||
"""
|
# """
|
||||||
if (
|
# if (
|
||||||
self.cam.acquire.get() != ACQUIREMODE.DONE.value
|
# self.cam.acquire.get() != ACQUIREMODE.DONE.value
|
||||||
or self.hdf.capture.get() != ACQUIREMODE.DONE.value
|
# or self.hdf.capture.get() != ACQUIREMODE.DONE.value
|
||||||
):
|
# ):
|
||||||
logger.warning(f"Can't start live mode, acquisition running on detector {self.name}.")
|
# logger.warning(f"Can't start live mode, acquisition running on detector {self.name}.")
|
||||||
return
|
# return
|
||||||
if self._live_mode_run_event.is_set():
|
# if self._live_mode_run_event.is_set():
|
||||||
logger.warning(f"Live mode is already running on detector {self.name}.")
|
# logger.warning(f"Live mode is already running on detector {self.name}.")
|
||||||
return
|
# return
|
||||||
|
|
||||||
# Set relevant PVs
|
# # Set relevant PVs
|
||||||
self.cam.array_counter.set(0).wait(5) # Reset array counter
|
# self.cam.array_counter.set(0).wait(5) # Reset array counter
|
||||||
self.cam.num_images.set(n_images_max).wait(5)
|
# self.cam.num_images.set(n_images_max).wait(5)
|
||||||
logger.info(
|
# logger.info(
|
||||||
f"Setting exposure time to {exp_time} s for live mode on {self.name} with {n_images_max} images."
|
# f"Setting exposure time to {exp_time} s for live mode on {self.name} with {n_images_max} images."
|
||||||
|
# )
|
||||||
|
# self.cam.acquire_time.set(exp_time - self._readout_time).wait(5)
|
||||||
|
# self.cam.acquire_period.set(exp_time).wait(5)
|
||||||
|
|
||||||
|
# status = CompareStatus(self.cam.acquire, ACQUIREMODE.DONE.value)
|
||||||
|
# # It should suffice to make sure that self.hdf.capture is not set..
|
||||||
|
# self.cam.acquire.put(1) # Start measurement
|
||||||
|
# try:
|
||||||
|
# status.wait(10)
|
||||||
|
# except WaitTimeoutError:
|
||||||
|
# content = traceback.format_exc()
|
||||||
|
# raise RuntimeError(
|
||||||
|
# f"Live Mode on detector {self.name} did not stop: {content} after 10s."
|
||||||
|
# )
|
||||||
|
# self._live_mode_run_event.set()
|
||||||
|
|
||||||
|
# def _live_mode_loop(self, exp_time: float):
|
||||||
|
# while not self._live_mode_kill_event.is_set():
|
||||||
|
# self._live_mode_run_event.wait()
|
||||||
|
# self._live_mode_stopped_event.clear() # Clear stopped event
|
||||||
|
# time.sleep(self._readout_time) # make sure to wait for the readout_time
|
||||||
|
# n_images = self.cam.array_counter.get()
|
||||||
|
# status = CompareStatus(self.cam.array_counter, n_images + 1)
|
||||||
|
# self.trigger_shot.put(1)
|
||||||
|
# try:
|
||||||
|
# status.wait(60)
|
||||||
|
# except WaitTimeoutError:
|
||||||
|
# logger.warning(
|
||||||
|
# f"Live mode timeout exceeded for {self.name}. Continuing in live_mode_loop"
|
||||||
|
# )
|
||||||
|
# if self._live_mode_run_event.is_set():
|
||||||
|
# self._live_mode_stopped_event.set() # Set stopped event to indicate that live mode loop is stopped
|
||||||
|
|
||||||
|
# def stop_live_mode(self):
|
||||||
|
# """Stop live mode."""
|
||||||
|
# if self._live_mode_stopped_event.is_set():
|
||||||
|
# return
|
||||||
|
# status = CompareStatus(self.cam.acquire, ACQUIREMODE.DONE.value)
|
||||||
|
# self.cam.acquire.put(0)
|
||||||
|
# self._live_mode_run_event.clear()
|
||||||
|
# if not self._live_mode_stopped_event.wait(10): # Wait until live mode loop is stopped
|
||||||
|
# logger.warning(f"Live mode did not stop in time for {self.name}.")
|
||||||
|
# try:
|
||||||
|
# status.wait(10)
|
||||||
|
# except WaitTimeoutError:
|
||||||
|
# content = traceback.format_exc()
|
||||||
|
# raise RuntimeError(
|
||||||
|
# f"Live Mode on detector {self.name} did not stop: {content} after 10s."
|
||||||
|
# )
|
||||||
|
|
||||||
|
def check_detector_stop_running_acquisition(self) -> AndStatusWithList:
|
||||||
|
"""Check if the detector is still running an acquisition."""
|
||||||
|
status_acquire = CompareStatus(self.cam.acquire, ACQUIREMODE.DONE.value)
|
||||||
|
status_writing = CompareStatus(self.hdf.capture, ACQUIREMODE.DONE.value)
|
||||||
|
status_cam_server = CompareStatus(self.cam.armed, DETECTORSTATE.UNARMED.value)
|
||||||
|
status = AndStatusWithList(
|
||||||
|
device=self, status_list=[status_acquire, status_writing, status_cam_server]
|
||||||
)
|
)
|
||||||
self.cam.acquire_time.set(exp_time - self._readout_time).wait(5)
|
return status
|
||||||
self.cam.acquire_period.set(exp_time).wait(5)
|
|
||||||
|
|
||||||
status = CompareStatus(self.cam.acquire, ACQUIREMODE.DONE.value)
|
|
||||||
# It should suffice to make sure that self.hdf.capture is not set..
|
|
||||||
self.cam.acquire.put(1) # Start measurement
|
|
||||||
try:
|
|
||||||
status.wait(10)
|
|
||||||
except WaitTimeoutError:
|
|
||||||
content = traceback.format_exc()
|
|
||||||
raise RuntimeError(
|
|
||||||
f"Live Mode on detector {self.name} did not stop: {content} after 10s."
|
|
||||||
)
|
|
||||||
self._live_mode_run_event.set()
|
|
||||||
|
|
||||||
def _live_mode_loop(self, exp_time: float):
|
|
||||||
while not self._live_mode_kill_event.is_set():
|
|
||||||
self._live_mode_run_event.wait()
|
|
||||||
self._live_mode_stopped_event.clear() # Clear stopped event
|
|
||||||
time.sleep(self._readout_time) # make sure to wait for the readout_time
|
|
||||||
n_images = self.cam.array_counter.get()
|
|
||||||
status = CompareStatus(self.cam.array_counter, n_images + 1)
|
|
||||||
self.trigger_shot.put(1)
|
|
||||||
try:
|
|
||||||
status.wait(60)
|
|
||||||
except WaitTimeoutError:
|
|
||||||
logger.warning(
|
|
||||||
f"Live mode timeout exceeded for {self.name}. Continuing in live_mode_loop"
|
|
||||||
)
|
|
||||||
if self._live_mode_run_event.is_set():
|
|
||||||
self._live_mode_stopped_event.set() # Set stopped event to indicate that live mode loop is stopped
|
|
||||||
|
|
||||||
def stop_live_mode(self):
|
|
||||||
"""Stop live mode."""
|
|
||||||
if self._live_mode_stopped_event.is_set():
|
|
||||||
return
|
|
||||||
status = CompareStatus(self.cam.acquire, ACQUIREMODE.DONE.value)
|
|
||||||
self.cam.acquire.put(0)
|
|
||||||
self._live_mode_run_event.clear()
|
|
||||||
if not self._live_mode_stopped_event.wait(10): # Wait until live mode loop is stopped
|
|
||||||
logger.warning(f"Live mode did not stop in time for {self.name}.")
|
|
||||||
try:
|
|
||||||
status.wait(10)
|
|
||||||
except WaitTimeoutError:
|
|
||||||
content = traceback.format_exc()
|
|
||||||
raise RuntimeError(
|
|
||||||
f"Live Mode on detector {self.name} did not stop: {content} after 10s."
|
|
||||||
)
|
|
||||||
|
|
||||||
########################################
|
########################################
|
||||||
# Beamline Specific Implementations #
|
# Beamline Specific Implementations #
|
||||||
@@ -342,7 +352,7 @@ class Pilatus(PSIDeviceBase, ADBase):
|
|||||||
Information about the upcoming scan can be accessed from the scan_info
|
Information about the upcoming scan can be accessed from the scan_info
|
||||||
(self.scan_info.msg) object.
|
(self.scan_info.msg) object.
|
||||||
"""
|
"""
|
||||||
self.stop_live_mode() # Make sure that live mode is stopped if scan runs
|
# self.stop_live_mode() # Make sure that live mode is stopped if scan runs
|
||||||
scan_msg: ScanStatusMessage = self.scan_info.msg
|
scan_msg: ScanStatusMessage = self.scan_info.msg
|
||||||
if scan_msg.scan_name.startswith("xas"):
|
if scan_msg.scan_name.startswith("xas"):
|
||||||
return None
|
return None
|
||||||
|
|||||||
Reference in New Issue
Block a user