From c7f2d81f94a229e87a3af83ffa473bffec35dd81 Mon Sep 17 00:00:00 2001 From: appel_c Date: Wed, 17 Sep 2025 12:55:28 +0200 Subject: [PATCH] working integration of timepix --- superxas_bec/devices/timepix/timepix.py | 40 +++++++++++++++---------- superxas_bec/devices/timepix/utils.py | 23 +++++++++----- 2 files changed, 39 insertions(+), 24 deletions(-) diff --git a/superxas_bec/devices/timepix/timepix.py b/superxas_bec/devices/timepix/timepix.py index 6575688..c82895a 100644 --- a/superxas_bec/devices/timepix/timepix.py +++ b/superxas_bec/devices/timepix/timepix.py @@ -18,7 +18,7 @@ from bec_lib.logger import bec_logger from ophyd import ADBase from ophyd import Component as Cpt from ophyd import DeviceStatus, Kind, StatusBase -from ophyd_devices import AsyncSignal, CompareStatus, TransitionStatus +from ophyd_devices import AsyncSignal, CompareStatus, PreviewSignal, TransitionStatus from ophyd_devices.devices.areadetector.cam import ASItpxCam from ophyd_devices.interfaces.base_classes.psi_device_base import PSIDeviceBase from typeguard import typechecked @@ -137,6 +137,14 @@ class Timepix(PSIDeviceBase, TimePixControl): max_size=1000, ) + preview = Cpt( + PreviewSignal, + name="preview", + ndim=2, + num_rotation_90=0, # Check this + doc="Preview signal for the Pilatus Detector", + ) + def __init__( self, *, @@ -215,12 +223,12 @@ class Timepix(PSIDeviceBase, TimePixControl): described in model .timepix_fly_client.timepix_fly_interface.TimepixEndFrame """ n_energy_points = start_frame.get("NumEnergyPoints", None) - if n_energy_points is None: - logger.error( - f"NumEnergyPoints not found in start_frame: {start_frame}. Have we received the correct frame?" - ) - return - # TODO What should we do here if n_energy_points and troin do not match with the expected values? + # if n_energy_points is None: + # logger.error( + # f"NumEnergyPoints not found in start_frame: {start_frame}. Have we received the correct frame?" + # ) + # return + # # TODO What should we do here if n_energy_points and troin do not match with the expected values? if n_energy_points != self._n_energy_points: logger.error( f"Number of energy points {n_energy_points} does not match expected {self._n_energy_points}." @@ -234,7 +242,7 @@ class Timepix(PSIDeviceBase, TimePixControl): tds_period = 0 tds_total_events = 0 if len(data_frames) == 0: - logger.info( + logger.error( f"No data frames received in msg_buffer; for start_frame: {start_frame}, end_frame: {end_frame}" ) else: @@ -336,16 +344,16 @@ class Timepix(PSIDeviceBase, TimePixControl): self.backend.on_connected() # Register the callback for processing data received by the backend # TODO add initial callback again once issues are resolved - # self.backend.add_callback(self.msg_buffer_callback) - self._msg_dump = [] + self.backend.add_callback(self.msg_buffer_callback) + # self._msg_dump = [] - def _on_msg_received(start_frame, data_frame, end_frame): - """Callback""" - self._msg_dump.append( - {"start_frame": start_frame, "data_frame": data_frame, "end_frame": end_frame} - ) + # def _on_msg_received(start_frame, data_frame, end_frame): + # """Callback""" + # self._msg_dump.append( + # {"start_frame": start_frame, "data_frame": data_frame, "end_frame": end_frame} + # ) - self.backend.add_callback(_on_msg_received) + # self.backend.add_callback(_on_msg_received) def on_stage(self) -> DeviceStatus | StatusBase | None: """ diff --git a/superxas_bec/devices/timepix/utils.py b/superxas_bec/devices/timepix/utils.py index d7c8634..1ec0f49 100644 --- a/superxas_bec/devices/timepix/utils.py +++ b/superxas_bec/devices/timepix/utils.py @@ -1,4 +1,4 @@ -"""Utility module for the Timepix detector.""" +"""Temporary utility module for Status Object implementations.""" from __future__ import annotations @@ -65,13 +65,20 @@ class AndStatusWithList(DeviceStatus): return False - # TODO Check if this actually works.... - def set_exception(self, exc): - with self._lock: - for st in self.all_statuses: - with st._lock: - if not st.done: - st.set_exception(exc) + # # TODO Check if this actually works.... + # def set_exception(self, exc): + # # Propagate the exception to all sub-statuses that are not done yet. + # + # with self._lock: + # if self._externally_initiated_completion: + # return + # if self.done: # Return if status is already done.. It must be resolved already + # return + # super().set_exception(exc) + # for st in self.all_statuses: + # with st._lock: + # if not st.done: + # st.set_exception(exc) def _run_callbacks(self): """