From ccbf50d837c34f390a089d89365b645a74e6eb75 Mon Sep 17 00:00:00 2001 From: appel_c Date: Fri, 8 Aug 2025 07:53:11 +0200 Subject: [PATCH] fix(undulator): fix setpoint and motor stop signal --- ophyd_devices/devices/undulator.py | 42 ++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/ophyd_devices/devices/undulator.py b/ophyd_devices/devices/undulator.py index 78a612d..b7c906b 100644 --- a/ophyd_devices/devices/undulator.py +++ b/ophyd_devices/devices/undulator.py @@ -24,11 +24,43 @@ class UNDULATORCONTROL(int, enum.Enum): BEAMLINE = 1 -class UndulatorEpicsSignal(EpicsSignal): +class UndulatorSetointSignal(EpicsSignal): """ SLS Undulator setpoint control """ + def put( + self, + value, + force=False, + connection_timeout=DEFAULT_CONNECTION_TIMEOUT, + callback=None, + use_complete=None, + timeout=DEFAULT_WRITE_TIMEOUT, + **kwargs, + ): + """ + Put a value to the setpoint PV. + + If the undulator is operator controlled, it will not move. + """ + if self.parent.select_control.get() == UNDULATORCONTROL.OPERATOR.value: + raise PermissionError("Undulator is operator controlled!") + return super().put( + value, + force=force, + connection_timeout=connection_timeout, + callback=callback, + use_complete=use_complete, + timeout=timeout, + **kwargs, + ) + + +class UndulatorStopSignal(EpicsSignal): + """ + SLS Undulator stop signal""" + def put( self, value, @@ -48,7 +80,7 @@ class UndulatorEpicsSignal(EpicsSignal): logger.error( f"Cannot use put for signal {self.name}; Undulator is operator controlled!" ) - return # Do not raise an error, just log it and return None. + return None return super().put( value, force=force, @@ -65,10 +97,10 @@ class UndulatorGap(PVPositioner): SLS Undulator gap control """ - setpoint = Cpt(UndulatorEpicsSignal, suffix="GAP-SP") - readback = Cpt(EpicsSignal, suffix="GAP-RBV", kind="hinted", auto_monitor=True) + setpoint = Cpt(UndulatorSetointSignal, suffix="GAP-SP") + readback = Cpt(EpicsSignalRO, suffix="GAP-RBV", kind="hinted", auto_monitor=True) - stop_signal = Cpt(UndulatorEpicsSignal, suffix="STOP") + stop_signal = Cpt(UndulatorStopSignal, suffix="STOP") done = Cpt(EpicsSignalRO, suffix="DONE", auto_monitor=True) select_control = Cpt(EpicsSignalRO, suffix="SCTRL", auto_monitor=True)