fix: use macros from dispatch

This commit is contained in:
perl_d committed 2026-07-31 12:21:14 +02:00
1 parent 1ef5b20172
commit b492face87
5 files changed
+30 -19

No files matched your search

@@ -1,6 +1,6 @@
import os
from aare.beamline_dispatch.protocols import AuthDispatch, BeamlineDispatch, BecMacros
from aare.beamline_dispatch.protocols import AuthDispatch, BeamlineDispatch
class DefaultAuthDispatch(AuthDispatch):
+1 -1
View File
@@ -10,7 +10,7 @@ class AuthDispatch(ABC):
class BecMacros(ABC):
@staticmethod
@abstractmethod
def save_and_reload(): ...
def save_and_reload() -> tuple[Any, Any]: ...
@staticmethod
@abstractmethod
def save_current_position(device, position, axis=None, force=False, max_delta=0.5) -> None: ...
@@ -11,11 +11,15 @@ class SimulatedAuthDispatch(AuthDispatch):
class SimulatedBecMacros(BecMacros):
@staticmethod
def save_and_reload(): ...
def save_and_reload() -> tuple[Any, Any]:
return (None, None)
@staticmethod
def save_current_position(device, position, axis=None, force=False, max_delta=0.5) -> None: ...
@staticmethod
def init_beamline_environment() -> tuple[Any, Any]: ...
def init_beamline_environment() -> tuple[Any, Any]:
return (None, None)
@staticmethod
def bl_energy(energy_ev, move_gap=True, mono_scan=True, plot=True): ...
@staticmethod
@@ -6,9 +6,16 @@ from aare.beamline_dispatch.protocols import BecMacros
class X10SaBecMacros(BecMacros):
def __init__(self) -> None:
from pxii_bec.macros.build_devices import save_and_reload, save_current_position
from pxii_bec.macros.init_beamline import init_beamline_environment
from pxii_bec.macros.pxii_energy import bl_energy, get_current_energy, mono_pitch_scan
from pxii_bec.macros.build_devices import ( # type: ignore
save_and_reload,
save_current_position,
)
from pxii_bec.macros.init_beamline import init_beamline_environment # type: ignore
from pxii_bec.macros.pxii_energy import ( # type: ignore
bl_energy,
get_current_energy,
mono_pitch_scan,
)
self.save_and_reload = save_and_reload
self.save_current_position = save_current_position
@@ -18,7 +25,7 @@ class X10SaBecMacros(BecMacros):
self.mono_pitch_scan = mono_pitch_scan
@staticmethod
def save_and_reload(): ...
def save_and_reload() -> tuple[Any, Any]: ...
@staticmethod
def save_current_position(device, position, axis=None, force=False, max_delta=0.5) -> None: ...
@staticmethod
+11 -11
View File
@@ -84,7 +84,7 @@ class BECClientWorker:
print(self.dev.keys())
self.scans = self.client.scans
self.macros = self.dispatch.bec_macros
self._load_user_macros()
self.client.macros._load_user_macros()
print(self._list_all_macros())
self.helper = FrontendProcedureHelper(self.client.connector)
self._set_scilog_tags()
@@ -301,7 +301,7 @@ class BECClientWorker:
self._raise_bec_error(e, operation="list_all_user_macros")
def _list_all_macros(self):
result = self.macros.list_user_macros()
result = self.client.macros.list_user_macros()
if result is None:
return []
return result
@@ -354,7 +354,7 @@ class BECClientWorker:
def mono_pitch_scan_runner(self, plot: bool = False):
try:
mono_pitch_scan(plot)
self.macros.mono_pitch_scan(plot)
except Exception as e:
self._raise_bec_error(e, operation="mono_pitch_scan", tags=["mono_pitch_scan"])
if self.beamline is MXBeamline.X06DA:
@@ -371,7 +371,7 @@ class BECClientWorker:
def check_current_energy(self):
"""Get the current energy from the BEC in eV"""
energy_ev = get_current_energy()
energy_ev = self.macros.get_current_energy()
energy_kev = energy_ev / 1000
return energy_kev
@@ -380,7 +380,7 @@ class BECClientWorker:
logger.info(f"Current energy: {current_energy:.1f} eV")
logger.info(f"Change energy requested: from {current_energy:.1f} to {value:.1f} eV")
try:
bl_energy(value, move_gap=False, mono_scan=True, plot=plot)
self.macros.bl_energy(value, move_gap=False, mono_scan=True, plot=plot)
except Exception as e:
self._raise_bec_error(
e,
@@ -496,20 +496,20 @@ class BECClientWorker:
)
def save_current_bs_pos(self):
save_current_position(self.dev.bs_z, "safe")
self.macros.save_current_position(self.dev.bs_z, "safe")
def save_current_collimator_pos(self):
save_current_position(self.dev.coll_y, "work")
self.macros.save_current_position(self.dev.coll_y, "work")
def save_current_aerotech_position(self):
save_current_position(self.dev.aerotech, "work", axis="x")
save_current_position(self.dev.aerotech, "work", axis="y")
save_current_position(self.dev.aerotech, "work", axis="z")
self.macros.save_current_position(self.dev.aerotech, "work", axis="x")
self.macros.save_current_position(self.dev.aerotech, "work", axis="y")
self.macros.save_current_position(self.dev.aerotech, "work", axis="z")
self.save_config_and_reload_devices()
def save_config_and_reload_devices(self):
self.position_devices, self.planner = save_and_reload()
self.position_devices, self.planner = self.macros.save_and_reload()
@property
def zoom(self):