From 3ea4e9195a7de18d79b6d55e689716d5b22d0ece Mon Sep 17 00:00:00 2001 From: x12sa Date: Thu, 7 May 2026 13:50:26 +0200 Subject: [PATCH 1/5] add example for 2-axis piezo controller in devoces/user_template.yaml --- csaxs_bec/device_configs/user_template.yaml | 22 +++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/csaxs_bec/device_configs/user_template.yaml b/csaxs_bec/device_configs/user_template.yaml index 689b53a..b635b65 100644 --- a/csaxs_bec/device_configs/user_template.yaml +++ b/csaxs_bec/device_configs/user_template.yaml @@ -50,7 +50,7 @@ rotx: ############################################################ npx: - description: nPoint x axis on the big npoint controller + description: nPoint x axis on the big (3-axis) npoint controller deviceClass: csaxs_bec.devices.npoint.npoint.NPointAxis deviceConfig: axis_Id: A @@ -68,7 +68,7 @@ npx: deviceTags: - npoint npy: - description: nPoint y axis on the big npoint controller + description: nPoint y axis on the big (3-axis) npoint controller deviceClass: csaxs_bec.devices.npoint.npoint.NPointAxis deviceConfig: axis_Id: B @@ -84,4 +84,22 @@ npy: readoutPriority: baseline connectionTimeout: 20 deviceTags: + - npoint +np2x: + description: nPoint x axis on the small (2-axis) npoint controller + deviceClass: csaxs_bec.devices.npoint.npoint.NPointAxis + deviceConfig: + axis_Id: A + host: "nPoint219026.psi.ch" + limits: + - -25 + - 25 + port: 23 + sign: 1 + enabled: true + onFailure: buffer + readOnly: false + readoutPriority: baseline + connectionTimeout: 20 + deviceTags: - npoint \ No newline at end of file -- 2.52.0 From 9b09d5a64de670ab6f85c95671e239da83af2f22 Mon Sep 17 00:00:00 2001 From: wakonig_k Date: Fri, 8 May 2026 09:22:30 +0200 Subject: [PATCH 2/5] feat(npoint): add retry to initial readout and improve error message --- csaxs_bec/devices/npoint/npoint.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) 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.""" -- 2.52.0 From 40e1efa3298017b08e513b9e56c84dd0ba5d06d9 Mon Sep 17 00:00:00 2001 From: wakonig_k Date: Tue, 12 May 2026 18:22:25 +0200 Subject: [PATCH 3/5] fix: rename settling_time to settle_time to override ophyd property --- csaxs_bec/devices/npoint/npoint.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/csaxs_bec/devices/npoint/npoint.py b/csaxs_bec/devices/npoint/npoint.py index 7fa38f2..fcf7d10 100644 --- a/csaxs_bec/devices/npoint/npoint.py +++ b/csaxs_bec/devices/npoint/npoint.py @@ -393,7 +393,7 @@ class NPointAxis(Device, PositionerBase): user_setpoint = Cpt(NpointSetpointSignal, signal_name="setpoint") motor_is_moving = Cpt(NpointMotorIsMoving, value=0, kind="normal") - settling_time = Cpt(Signal, value=0.1, kind="config") + settle_time: Cpt[Signal] = Cpt(Signal, value=0.1, kind="config") high_limit_travel = Cpt(Signal, value=0, kind="omitted") low_limit_travel = Cpt(Signal, value=0, kind="omitted") @@ -543,7 +543,7 @@ class NPointAxis(Device, PositionerBase): self.motor_is_moving.set_motor_is_moving(1) val = self.readback.read() self._run_subs(sub_type=self.SUB_READBACK, value=val, timestamp=time.time()) - time.sleep(self.settling_time.get()) + time.sleep(max(self.settle_time.get(), 0)) self.motor_is_moving.set_motor_is_moving(0) val = self.readback.read() self._run_subs(sub_type=self.SUB_READBACK, value=val, timestamp=time.time()) -- 2.52.0 From a4d8c570e147fd54042a45be12f21ec399d30e12 Mon Sep 17 00:00:00 2001 From: x12sa Date: Wed, 13 May 2026 16:05:49 +0200 Subject: [PATCH 4/5] add settle time to npoint user template --- csaxs_bec/device_configs/user_template.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/csaxs_bec/device_configs/user_template.yaml b/csaxs_bec/device_configs/user_template.yaml index b635b65..09694b0 100644 --- a/csaxs_bec/device_configs/user_template.yaml +++ b/csaxs_bec/device_configs/user_template.yaml @@ -60,6 +60,7 @@ npx: - 50 port: 23 sign: 1 + settle_time: 0.1 enabled: true onFailure: buffer readOnly: false @@ -78,6 +79,7 @@ npy: - 50 port: 23 sign: 1 + settle_time: 0.1 enabled: true onFailure: buffer readOnly: false @@ -96,6 +98,7 @@ np2x: - 25 port: 23 sign: 1 + settle_time: 0.08 enabled: true onFailure: buffer readOnly: false -- 2.52.0 From abca4364bda753347004c09fbcb63e9133fcee68 Mon Sep 17 00:00:00 2001 From: x12sa Date: Wed, 13 May 2026 16:06:19 +0200 Subject: [PATCH 5/5] 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.""" -- 2.52.0