From 2a7b068cc67e91c443417a55be7ada335b34ce46 Mon Sep 17 00:00:00 2001 From: wyzula-jan Date: Mon, 10 Nov 2025 14:35:57 +0100 Subject: [PATCH] fix(ids_camera): live mode signal --- csaxs_bec/devices/ids_cameras/ids_camera.py | 36 ++++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/csaxs_bec/devices/ids_cameras/ids_camera.py b/csaxs_bec/devices/ids_cameras/ids_camera.py index 750e877..40c0862 100644 --- a/csaxs_bec/devices/ids_cameras/ids_camera.py +++ b/csaxs_bec/devices/ids_cameras/ids_camera.py @@ -3,21 +3,19 @@ from __future__ import annotations import threading -import time -from typing import TYPE_CHECKING, Literal, Tuple, TypedDict +from typing import TYPE_CHECKING, Literal import numpy as np +from ophyd import Component as Cpt, Signal, Kind + from bec_lib import messages from bec_lib.logger import bec_logger -from ophyd import Component as Cpt +from csaxs_bec.devices.ids_cameras.base_integration.camera import Camera from ophyd_devices.interfaces.base_classes.psi_device_base import PSIDeviceBase from ophyd_devices.utils.bec_signals import AsyncSignal, PreviewSignal -from csaxs_bec.devices.ids_cameras.base_integration.camera import Camera - if TYPE_CHECKING: from bec_lib.devicemanager import ScanInfo - from pydantic import ValidationInfo logger = bec_logger.logger @@ -45,6 +43,7 @@ class IDSCamera(PSIDeviceBase): doc="Signal for the region of interest (ROI).", async_update={"type": "add", "max_shape": [None]}, ) + live_mode_enabled = Cpt(Signal, name="live_mode_enabled", value=False ,doc="Enable or disable live mode.",kind=Kind.config) USER_ACCESS = ["live_mode", "mask", "set_rect_roi", "get_last_image"] @@ -83,12 +82,13 @@ class IDSCamera(PSIDeviceBase): bits_per_pixel=bits_per_pixel, connect=False, ) - self._live_mode = False self._inputs = {"live_mode": live_mode} self._mask = np.zeros((1, 1), dtype=np.uint8) self.image.num_rotation_90 = num_rotation_90 self.image.transpose = transpose self._force_monochrome = force_monochrome + self.live_mode_enabled.subscribe(self.on_live_mode_changed,run=False) + self.live_mode_enabled.put(live_mode) ############## Live Mode Methods ############## @@ -117,19 +117,23 @@ class IDSCamera(PSIDeviceBase): @property def live_mode(self) -> bool: """Return whether the camera is in live mode.""" - return self._live_mode + return bool(self.live_mode_enabled.get()) @live_mode.setter def live_mode(self, value: bool): """Set the live mode for the camera.""" - if value != self._live_mode: - if self.cam._connected is False: # $ pylint: disable=protected-access - self.cam.on_connect() - self._live_mode = value - if value: - self._start_live() - else: - self._stop_live() + if value != bool(self.live_mode_enabled.get()): + self.live_mode_enabled.put(bool(value)) + + def on_live_mode_changed(self, *args, value, **kwargs): + """Callback for when live mode is changed.""" + if self.cam._connected is False: # $ pylint: disable=protected-access + self.cam.on_connect() + self.live_mode_enabled.put(bool(value)) + if value: + self._start_live() + else: + self._stop_live() def set_rect_roi(self, x: int, y: int, width: int, height: int): """Set the rectangular region of interest (ROI) for the camera."""