From abca4364bda753347004c09fbcb63e9133fcee68 Mon Sep 17 00:00:00 2001 From: x12sa Date: Wed, 13 May 2026 16:06:19 +0200 Subject: [PATCH] fix(npoint): retry on wait_for_connection --- csaxs_bec/devices/npoint/npoint.py | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/csaxs_bec/devices/npoint/npoint.py b/csaxs_bec/devices/npoint/npoint.py index fcf7d10..0ab3589 100644 --- a/csaxs_bec/devices/npoint/npoint.py +++ b/csaxs_bec/devices/npoint/npoint.py @@ -448,26 +448,14 @@ class NPointAxis(Device, PositionerBase): self.high_limit_travel.put(limits[1]) def wait_for_connection(self, timeout: float = 30.0) -> bool: - self.controller.on(timeout=timeout) - self._update_setpoint_from_readback() - - def _update_setpoint_from_readback(self): - """ - The setpoint is only stored locally. After a restart, - we need to update it to match the current readback value. - """ - for attempt in range(5): + for _ 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}" - ) + self.controller.on(timeout=timeout) + self._update_setpoint_from_readback() + except TimeoutError: + self.controller.off(update_config=False) 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( @@ -475,6 +463,13 @@ class NPointAxis(Device, PositionerBase): 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 _update_setpoint_from_readback(self): + """ + 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() def destroy(self): """Make sure to turn off the controller socket on destroy."""