fix/slits_show_all working again

This commit is contained in:
x12sa
2026-06-30 14:31:36 +02:00
committed by holler
co-authored by holler
parent 716e2e8e61
commit 05ef894e4a
@@ -19,6 +19,16 @@ class cSAXSSlits:
User-visible slits namespace.
"""
# device name prefix -> human-readable label
_SLIT_LABELS = {
"sl1": "Slit 1 (frontend)",
"sl2": "Slit 2 (optics, slit 1)",
"sl3": "Slit 3 (optics, slit 2)",
"sl4": "Slit 4 (exposure box 1, entrance)",
"sl5": "Slit 5 (exposure box 1, exit)",
"sl6": "Slit 6 (exposure box 2)",
}
def __init__(self, client):
self.client = client
self.device_manager = client.device_manager
@@ -28,27 +38,20 @@ class cSAXSSlits:
# --------------------------------------------------------
def _sl_get_position(self, device_name: str) -> Optional[float]:
"""
Safely return the position of a device or None.
"""
try:
device = self.device_manager.devices[device_name]
except Exception:
return None
"""
Safely return the position of a device or None.
"""
try:
device = self.device_manager.devices[device_name]
except Exception:
return None
try:
if hasattr(device, "readback"):
return device.readback.get()
except Exception:
pass
try:
if hasattr(device, "get"):
return device.get()
except Exception:
pass
return None
try:
reading = device.read()
value = reading[device_name]["value"]
return float(value)
except Exception:
return None
@staticmethod
def _sl_fmt(value: Optional[float]) -> str:
@@ -62,53 +65,27 @@ class cSAXSSlits:
def slits_show_all(self):
"""
Show all slits with center and width.
Show all slits with x/y center and size.
"""
print("")
print("========== cSAXS Slits Overview ==========")
print("")
# Slit 1
print("Slit 1 (frontend):")
ch = self._sl_get_position("sl1xc")
wh = self._sl_get_position("sl1xs")
cv = self._sl_get_position("sl1yc")
wv = self._sl_get_position("sl1ys")
print(
f" center horizontal = {self._sl_fmt(ch)} "
f"width horizontal = {self._sl_fmt(wh)}"
)
print(
f" center vertical = {self._sl_fmt(cv)} "
f"width vertical = {self._sl_fmt(wv)}"
)
print("")
# Slits 35
slit_map = {
3: "exposure box 2 entrance",
4: "exposure box 2 exit",
5: "exposure box 3",
}
for slit, label in slit_map.items():
print(f"Slit {slit} ({label}):")
ch = self._sl_get_position(f"sl{slit}ch")
wh = self._sl_get_position(f"sl{slit}wh")
cv = self._sl_get_position(f"sl{slit}cv")
wv = self._sl_get_position(f"sl{slit}wv")
for prefix, label in self._SLIT_LABELS.items():
xc = self._sl_get_position(f"{prefix}xc")
xs = self._sl_get_position(f"{prefix}xs")
yc = self._sl_get_position(f"{prefix}yc")
ys = self._sl_get_position(f"{prefix}ys")
print(f"{label}:")
print(
f" center horizontal = {self._sl_fmt(ch)} "
f"width horizontal = {self._sl_fmt(wh)}"
f" x center = {self._sl_fmt(xc)} "
f"x size = {self._sl_fmt(xs)}"
)
print(
f" center vertical = {self._sl_fmt(cv)} "
f"width vertical = {self._sl_fmt(wv)}"
f" y center = {self._sl_fmt(yc)} "
f"y size = {self._sl_fmt(ys)}"
)
print("")