From aabeb59cd1cc4054a0da4e4ec09e0139f63a934b Mon Sep 17 00:00:00 2001 From: appel_c Date: Fri, 15 Aug 2025 10:27:05 +0200 Subject: [PATCH] w --- superxas_bec/devices/timepix/timepix.py | 22 +++++++++++++++++-- .../timepix_fly_client/timepix_fly_backend.py | 2 +- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/superxas_bec/devices/timepix/timepix.py b/superxas_bec/devices/timepix/timepix.py index 07c3a6f..8a8d6f4 100644 --- a/superxas_bec/devices/timepix/timepix.py +++ b/superxas_bec/devices/timepix/timepix.py @@ -21,6 +21,7 @@ from ophyd_devices.interfaces.base_classes.psi_device_base import PSIDeviceBase from typeguard import typechecked from superxas_bec.devices.timepix.timepix_fly_client.timepix_fly_backend import TimepixFlyBackend +from superxas_bec.devices.timepix.timepix_fly_client.timepix_fly_client import TimePixFlyStatus from superxas_bec.devices.timepix.timepix_fly_client.timepix_fly_interface import ( OtherConfigModel, PixelMap, @@ -366,7 +367,8 @@ class Timepix(PSIDeviceBase, TimePixControl): def trigger_callback(status: DeviceStatus): """Trigger callback to start the acquisition.""" - status.device.cam.acquire.put(1) + if status.done: + status.device.cam.acquire.put(1) # Detector will be ready to start, as either pre_scan or the status_camera from a previous # trigger will ensure that the detector is in ACQUIRESTATUS.DONE state. @@ -381,8 +383,24 @@ class Timepix(PSIDeviceBase, TimePixControl): self.cam.acquire_busy, [ACQUIRESTATUS.ACQUIRING, ACQUIRESTATUS.DONE] ) + # TODO cleanup and test + def failed_to_start_collect_cb(status: DeviceStatus): + """Callback to handle failure to start the collect.""" + if not status.done: + logger.error("Failed to start collect on Timepix Fly backend.") + status.device.backend.timepix_fly_client.stop_collect() + + status_collect_backend = DeviceStatus(self, timeout=10) + status_collect_backend.add_callback(failed_to_start_collect_cb) + self.backend.timepix_fly_client.add_status_callback( + status=status_collect_backend, + success=[TimePixFlyStatus.COLLECT], + error=[TimePixFlyStatus.EXCEPT, TimePixFlyStatus.SHUTDOWN], + ) + status = AndStatus(status_backend, status_camera) - self.cancel_on_stop(status) + st = AndStatus(status, status_collect_backend) + self.cancel_on_stop(st) # NOTE, the callback to sent the data will always be called from the backend # as it is attached via self.backend.add_callback() in on_connected. return status diff --git a/superxas_bec/devices/timepix/timepix_fly_client/timepix_fly_backend.py b/superxas_bec/devices/timepix/timepix_fly_client/timepix_fly_backend.py index 1d3fdf3..13ca2a3 100644 --- a/superxas_bec/devices/timepix/timepix_fly_client/timepix_fly_backend.py +++ b/superxas_bec/devices/timepix/timepix_fly_client/timepix_fly_backend.py @@ -340,7 +340,7 @@ if __name__ == "__main__": # pragma: no cover ) timepix.on_stage(other_config=config, pixel_map=pixel_map) print("TimepixFlyBackend staged with configuration and pixel map.") - for ii in range(10): + for ii in range(100): print(f"Starting scan {ii + 1}...;") # time.sleep(1) status_1 = timepix.on_trigger()