diff --git a/csaxs_bec/devices/npoint/npoint.py b/csaxs_bec/devices/npoint/npoint.py index 481b30e..7fa38f2 100644 --- a/csaxs_bec/devices/npoint/npoint.py +++ b/csaxs_bec/devices/npoint/npoint.py @@ -3,6 +3,7 @@ import threading import time import numpy as np +from bec_lib.logger import bec_logger from ophyd import Component as Cpt from ophyd import Device, PositionerBase, Signal, SignalRO from ophyd.status import wait as status_wait @@ -11,6 +12,8 @@ from ophyd_devices.utils.controller import Controller, threadlocked from ophyd_devices.utils.socket import SocketIO, SocketSignal, raise_if_disconnected from prettytable import PrettyTable +logger = bec_logger.logger + def channel_checked(fcn): """Decorator to catch attempted access to channels that are not available.""" @@ -453,7 +456,25 @@ class NPointAxis(Device, PositionerBase): The setpoint is only stored locally. After a restart, we need to update it to match the current readback value. """ - self.user_setpoint.setpoint = self.readback.get() + for attempt in range(5): + try: + self.user_setpoint.setpoint = self.readback.get() + except Exception as e: + logger.warning( + f"NPointAxis {self.name}: Failed to update the setpoint from the readback value on attempt {attempt+1} during startup: {e}" + ) + time.sleep(1) + else: + logger.info( + f"NPointAxis {self.name}: Successfully updated the setpoint from the readback value on attempt {attempt+1} during startup." + ) + break + else: + raise TimeoutError( + f"NPointAxis {self.name}: Failed to update the setpoint from the readback value after 5 attempts during startup. This may happen occasionally. " + f"Try to reload the config and if the problem persists, check the connection to the nPoint controller " + f"and ensure that it is powered on and accessible at {self.controller._socket_host}:{self.controller._socket_port}." + ) def destroy(self): """Make sure to turn off the controller socket on destroy."""