DAQ: trying to fix bug by making status and geomertry calls safe...

This commit is contained in:
appleb_m committed 2026-03-31 13:47:14 +02:00
1 parent 12e0d2cb56
commit d136255543
1 file changed
+32 -36
+32 -36
View File
@@ -1794,48 +1794,44 @@ class AareDAQ:
_ = self.__devs.aerotech.status()
except Exception as e:
aerotech_ok = False
aerotech_err = str(e)
aerotech_err = f"Cannot connect to Aerotech: {e}"
return aerotech_ok, aerotech_err
def _safe_geom(self) -> tuple[SampleGeometryModel, bool, str | None]:
def _safe_geom(self) -> tuple[SampleGeometryModel, bool, str | None, bool, str | None]:
"""
Return (geom, smargon_connected, smargon_error) without raising.
Return (geom, smargon_connected, smargon_error, aerotech_connected, aerotech_error) without raising.
Uses a conservative fallback geometry if Smargon access fails.
"""
aerotech_connected, smargon_connected = True, True
aerotech_error, smargon_error = None, None
try:
return self.sample_geometry, True, None
return self.sample_geometry, smargon_connected, smargon_error, aerotech_connected, aerotech_error
except SmargonCommunicationError as e:
zoom = self.__devs.zoom
fallback = SampleGeometryModel(
beam_location_pxl=self.__cfg.beam_mark_coeff.apply(zoom),
pixel_in_mm=self.__cfg.pixel_to_mm(zoom),
omega_deg=self.__devs.aerotech_omega,
smargon=SmargonCoordinate(
sh_mm=Coordinate(x=0.0, y=0.0, z=0.0),
phi_deg=0.0,
chi_deg=0.0,
),
beam_size_mm=self.__cfg.beam_size_mm,
aerotech=Coordinate(x=0.0, y=0.0, z=0.0),
aerotech_meas=Coordinate(x=0.0, y=0.0, z=0.0),
)
return fallback, False, str(e)
smargon_error = f"Cannot connect to Smargon: {e}"
smargon_connected = False
except AerotechCommunicationError as e:
aerotech_error = f"Cannot connect to Aerotech: {e}"
aerotech_connected = False
except Exception as e:
zoom = self.__devs.zoom
fallback = SampleGeometryModel(
beam_location_pxl=self.__cfg.beam_mark_coeff.apply(zoom),
pixel_in_mm=self.__cfg.pixel_to_mm(zoom),
omega_deg=self.__devs.aerotech_omega,
smargon=SmargonCoordinate(
sh_mm=Coordinate(x=0.0, y=0.0, z=0.0),
phi_deg=0.0,
chi_deg=0.0,
),
beam_size_mm=self.__cfg.beam_size_mm,
aerotech=Coordinate(x=0.0, y=0.0, z=0.0),
aerotech_meas=Coordinate(x=0.0, y=0.0, z=0.0),
)
return fallback, False, f"Smargon unavailable: {e}"
smargon_error = f"Safe geometry failed: {e}"
aerotech_error = f"Safe geometry failed: {e}"
aerotech_connected = False
smargon_connected = False
zoom = self.__devs.zoom
fallback = SampleGeometryModel(
beam_location_pxl=self.__cfg.beam_mark_coeff.apply(zoom),
pixel_in_mm=self.__cfg.pixel_to_mm(zoom),
omega_deg=0.0,
smargon=SmargonCoordinate(
sh_mm=Coordinate(x=0.0, y=0.0, z=0.0),
phi_deg=0.0,
chi_deg=0.0,
),
beam_size_mm=self.__cfg.beam_size_mm,
aerotech=Coordinate(x=0.0, y=0.0, z=0.0),
aerotech_meas=Coordinate(x=0.0, y=0.0, z=0.0),
)
return fallback, smargon_connected, smargon_error, aerotech_connected, aerotech_error
def _safe_beamline_status(self) -> BeamlineStatus:
try:
@@ -1878,8 +1874,8 @@ class AareDAQ:
@property
def status(self) -> DAQStatusModel:
safe_sample, tell_ok, tell_err = self._safe_sample()
safe_geom, smargon_ok, smargon_err = self._safe_geom()
aerotech_ok, aerotech_err = self._aerotech_status()
safe_geom, smargon_ok, smargon_err, aerotech_ok, aerotech_err = self._safe_geom()
return DAQStatusModel(
state=self.state,