From afcbbf66ccafa653772f316bf4cc1c1285628c70 Mon Sep 17 00:00:00 2001 From: x01dc Date: Sun, 12 Jul 2026 07:47:01 +0200 Subject: [PATCH] fix/galil back to original code --- csaxs_bec/devices/omny/galil/fgalil_ophyd.py | 2 ++ csaxs_bec/devices/omny/galil/galil_ophyd.py | 2 ++ csaxs_bec/devices/sim/sim_galil.py | 9 ++++++--- docs/SIMULATED_ENDSTATIONS.md | 13 +++++++------ 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/csaxs_bec/devices/omny/galil/fgalil_ophyd.py b/csaxs_bec/devices/omny/galil/fgalil_ophyd.py index b03cd63..0444295 100644 --- a/csaxs_bec/devices/omny/galil/fgalil_ophyd.py +++ b/csaxs_bec/devices/omny/galil/fgalil_ophyd.py @@ -123,6 +123,8 @@ class FlomniGalilSetpointSignal(GalilSetpointSignal): self.controller.socket_put_confirmed(f"ntarget={target_val:.3f}") self.controller.socket_put_confirmed("movereq=1") self.controller.socket_put_confirmed("XQ#NEWPAR") + while self.controller.is_thread_active(0): + time.sleep(0.005) else: raise GalilError("Not all axes are referenced.") diff --git a/csaxs_bec/devices/omny/galil/galil_ophyd.py b/csaxs_bec/devices/omny/galil/galil_ophyd.py index 063e2b0..217bd6f 100644 --- a/csaxs_bec/devices/omny/galil/galil_ophyd.py +++ b/csaxs_bec/devices/omny/galil/galil_ophyd.py @@ -427,6 +427,8 @@ class GalilSetpointSignal(GalilSignalBase): self.controller.socket_put_confirmed(f"ntarget={target_val:.3f}") self.controller.socket_put_confirmed("movereq=1") self.controller.socket_put_confirmed("XQ#NEWPAR") + while self.controller.is_thread_active(0): + time.sleep(0.005) else: raise GalilError("Not all axes are referenced.") diff --git a/csaxs_bec/devices/sim/sim_galil.py b/csaxs_bec/devices/sim/sim_galil.py index 247c5f8..f80e2a6 100644 --- a/csaxs_bec/devices/sim/sim_galil.py +++ b/csaxs_bec/devices/sim/sim_galil.py @@ -182,9 +182,11 @@ class SimGalilState: self.recompute_allaxref() def thread_active(self, thread_id: int) -> bool: - if thread_id == 0: - if any(ax.is_moving() for ax in self.axes): - return True + # thread 0 only dispatches moves (#NEWPAR) and runs referencing (#FES); on the + # real controller it is active for milliseconds while the motion itself is + # carried by the firmware (MG_BG) - modeled via short deadlines, NOT by axis + # motion. This keeps the trailing thread-0 wait in the real setpoint code + # returning quickly, as on real hardware. if thread_id == 3: if self._transfer_thread is not None and self._transfer_thread.is_alive(): return True @@ -222,6 +224,7 @@ class SimGalilState: self._tracker_running = False def start_move_from_newpar(self): + self.set_thread_active(0, 0.05) # dispatch window with self.lock: if self.variables.get("movereq", 0.0) != 1.0: return diff --git a/docs/SIMULATED_ENDSTATIONS.md b/docs/SIMULATED_ENDSTATIONS.md index 954fb93..412a90f 100644 --- a/docs/SIMULATED_ENDSTATIONS.md +++ b/docs/SIMULATED_ENDSTATIONS.md @@ -69,10 +69,6 @@ Protocol fidelity is grounded in the actual hardware-side sources: `fgalil.dmc`, ## Real-code fixes made along the way (separate commits) -- `fgalil_ophyd.py` and `galil_ophyd.py` (base class, affects LamNI/OMNY): removed the - trailing thread-0 wait in the setpoint `_socket_set` — it blocked `user_setpoint.put()` (holding the - controller lock) for the whole move, so no intermediate readback/progress was possible. - Applies to the real instrument too. - `ddg_1.py`: `bec_server.scan_server...ScanInfo` import moved under `TYPE_CHECKING` (typing-only runtime dependency broke against the redeployed BEC layout). - `flomni.py`: all four scilog sends wrapped in try/except RuntimeError — accounts @@ -82,8 +78,7 @@ Protocol fidelity is grounded in the actual hardware-side sources: `fgalil.dmc`, Tarballs contain ONLY simulation-package files (`devices/sim/*` except `simulated_beamline_devices.py`, `device_configs/simulated_omny/*`, generator, harnesses, -this doc) plus the two agreed device-layer fixes (`galil_ophyd.py`, `fgalil_ophyd.py`, -`ddg_1.py`). Fixes to user-maintained files (`flomni.py`, ...) are delivered as diffs +this doc) plus the single agreed device-layer fix (`ddg_1.py`). Fixes to user-maintained files (`flomni.py`, ...) are delivered as diffs only — never as full files, since the working copies evolve during testing. ## BEC integration lessons (important for future sim devices) @@ -118,6 +113,12 @@ only — never as full files, since the working copies evolve during testing. scan plugin) — starting a scan with user-disabled feedback therefore works, on the real system as well as in the sim; it only fails on real hardware when feedback cannot engage (air on, interferometer error), an error mode deliberately not simulated. +- Thread 0 is dispatch-only, as on the real controller: `#NEWPAR` keeps it active for + ~50 ms while the motion itself is reported via the firmware flags (`MG_BG`, motor on). + The trailing thread-0 wait in the (unmodified) setpoint code therefore returns quickly + and move progress is published, matching real hardware. An earlier sim iteration + wrongly modeled thread 0 as busy for the whole move and "fixed" the device code to + match — that change was reverted; the device files are untouched. - Referencing (`#FES/#FRM/#REFAX`) applies its outcome synchronously (limit switch, position 0) while only the apparent motion is time-based, so status polls never race the result.