better erro hadnling for status bar
This commit is contained in:
@@ -137,6 +137,7 @@ class DAQWorker(QObject):
|
||||
self._status_request_min_interval = 0.5
|
||||
self._smargon_retry_interval_s = 2.0
|
||||
self._smargon_log_min_interval_s = 10.0
|
||||
self._last_status_can_read: bool | None = None
|
||||
|
||||
self._device_error_log_min_interval_s = 10.0
|
||||
self._last_device_error_log_ts: dict[str, float] = {"tell": 0.0, "smargon": 0.0}
|
||||
|
||||
@@ -132,88 +132,92 @@ class StatusBar(QStatusBar):
|
||||
|
||||
@Slot(DAQStatusModel)
|
||||
def update_daq_status(self, status: DAQStatusModel):
|
||||
self.__status = status
|
||||
if status.bl.flux_ph_s is None:
|
||||
self.flux.set_value(f"0")
|
||||
else:
|
||||
self.flux.set_value(f"{(status.bl.flux_ph_s / 1e9):.0f}")
|
||||
|
||||
if status.bl.transmission is None:
|
||||
self.transmission.set_value(f"(moving)")
|
||||
else:
|
||||
self.transmission.set_value(f"{status.bl.transmission:.5f}")
|
||||
|
||||
if status.bl.ring_current_mA < 5.0:
|
||||
self.ring_current.set_value(f"{status.bl.ring_current_mA:.2f}", "red")
|
||||
elif status.bl.ring_current_mA < 390.0:
|
||||
self.ring_current.set_value(f"{status.bl.ring_current_mA:.2f}", "orange")
|
||||
else:
|
||||
self.ring_current.set_value(f"{status.bl.ring_current_mA:.2f}")
|
||||
|
||||
self.wvl.set_value(f"{status.diffraction.wavelength_angstrom:.2f}")
|
||||
|
||||
if status.bl.cryojet_K < 110.0:
|
||||
self.cryo_label.set_value(f"{status.bl.cryojet_K:.1f}", "blue")
|
||||
elif status.bl.cryojet_K < 250.0:
|
||||
self.cryo_label.set_value(f"{status.bl.cryojet_K:.1f}", "orange")
|
||||
else:
|
||||
self.cryo_label.set_value(f"{status.bl.cryojet_K:.1f}", "red")
|
||||
|
||||
if status.bl.shutter_open:
|
||||
self.shutter_label.setText(f"""Shutter: <span style="color: red ; "> Open ☢️ </span>""")
|
||||
else:
|
||||
self.shutter_label.setText(f"""Shutter: <span style="color: green ; "> Closed 🚪 </span>""")
|
||||
|
||||
if status.bl.exp_shutter_open:
|
||||
self.exp_shutter_label.setText("""ExpHutch Shutter: <span style="color: red ; "> Open </span>""")
|
||||
else:
|
||||
self.exp_shutter_label.setText("""ExpHutch Shutter: <span style="color: green ; "> Closed 🚪 </span>""")
|
||||
|
||||
if status.session.current_pgroup is not None:
|
||||
self.pgroup_label.setText(f"""p-group: {status.session.current_pgroup} """)
|
||||
else:
|
||||
self.pgroup_label.setText(f"Inactive p-group ")
|
||||
|
||||
self.state_label.setText(f"""State: {status.state.display_name()} """)
|
||||
|
||||
tell_text = "—"
|
||||
tell_color = "rgb(55, 67, 87)"
|
||||
if status.tell_state is not None:
|
||||
tell_text = status.tell_state.activity.display_name()
|
||||
|
||||
if status.tell_state.activity.value == "error":
|
||||
tell_color = "red"
|
||||
elif status.tell_state.activity.value in {"mounting", "unmounting", "drying", "cooling"}:
|
||||
tell_color = "orange"
|
||||
try:
|
||||
self.__status = status
|
||||
if status.bl.flux_ph_s is None:
|
||||
self.flux.set_value(f"0")
|
||||
else:
|
||||
tell_color = "green"
|
||||
self.flux.set_value(f"{(status.bl.flux_ph_s / 1e9):.0f}")
|
||||
|
||||
self.tell_state_label.setText(f"Tell: {tell_text} ")
|
||||
self.tell_state_label.setStyleSheet(f"color: {tell_color};")
|
||||
if status.bl.transmission is None:
|
||||
self.transmission.set_value(f"(moving)")
|
||||
else:
|
||||
self.transmission.set_value(f"{status.bl.transmission:.5f}")
|
||||
|
||||
if status.busy:
|
||||
busy_flag = """ <span style="color: red; "> Busy 🔒 </span>"""
|
||||
else:
|
||||
busy_flag = """ <span style="color: green ; "> Idle 🔓 </span>"""
|
||||
if status.bl.ring_current_mA < 5.0:
|
||||
self.ring_current.set_value(f"{status.bl.ring_current_mA:.2f}", "red")
|
||||
elif status.bl.ring_current_mA < 390.0:
|
||||
self.ring_current.set_value(f"{status.bl.ring_current_mA:.2f}", "orange")
|
||||
else:
|
||||
self.ring_current.set_value(f"{status.bl.ring_current_mA:.2f}")
|
||||
|
||||
html_content = f"""Beamline: {busy_flag} """
|
||||
if status.diffraction.wavelength_angstrom:
|
||||
self.wvl.set_value(f"{status.diffraction.wavelength_angstrom:.2f}")
|
||||
|
||||
self.busy_label.setText(html_content)
|
||||
if status.bl.cryojet_K < 110.0:
|
||||
self.cryo_label.set_value(f"{status.bl.cryojet_K:.1f}", "blue")
|
||||
elif status.bl.cryojet_K < 250.0:
|
||||
self.cryo_label.set_value(f"{status.bl.cryojet_K:.1f}", "orange")
|
||||
else:
|
||||
self.cryo_label.set_value(f"{status.bl.cryojet_K:.1f}", "red")
|
||||
|
||||
session_flag = ""
|
||||
if status.session.session == SessionsStateEnum.Vacant:
|
||||
session_flag = """<span style="color: yellow ; "> Vacant 🔓 </span>"""
|
||||
elif status.session.session == SessionsStateEnum.OwnedByYou:
|
||||
session_flag = """<span style="color: green ; "> Owned ⬤ </span>"""
|
||||
elif status.session.session == SessionsStateEnum.OwnedByElse:
|
||||
session_flag = """<span style="color: red ; "> Other 🔒 </span>"""
|
||||
elif status.session.session == SessionsStateEnum.PendingYouToElse:
|
||||
session_flag = """<span style="color: orange ; "> Waiting... ⏳ </span>"""
|
||||
elif status.session.session == SessionsStateEnum.PendingElseToYou:
|
||||
session_flag = """<span style="color: cyan ; "> Request! ⚡ </span>"""
|
||||
if status.bl.shutter_open:
|
||||
self.shutter_label.setText(f"""Shutter: <span style="color: red ; "> Open ☢️ </span>""")
|
||||
else:
|
||||
self.shutter_label.setText(f"""Shutter: <span style="color: green ; "> Closed 🚪 </span>""")
|
||||
|
||||
html_content_session = f"""Session: {session_flag}"""
|
||||
self.session_label.setText(html_content_session)
|
||||
if status.bl.exp_shutter_open:
|
||||
self.exp_shutter_label.setText("""ExpHutch Shutter: <span style="color: red ; "> Open </span>""")
|
||||
else:
|
||||
self.exp_shutter_label.setText("""ExpHutch Shutter: <span style="color: green ; "> Closed 🚪 </span>""")
|
||||
|
||||
if status.session.current_pgroup is not None:
|
||||
self.pgroup_label.setText(f"""p-group: {status.session.current_pgroup} """)
|
||||
else:
|
||||
self.pgroup_label.setText(f"Inactive p-group ")
|
||||
|
||||
self.state_label.setText(f"""State: {status.state.display_name()} """)
|
||||
|
||||
tell_text = "—"
|
||||
tell_color = "rgb(55, 67, 87)"
|
||||
if status.tell_state is not None:
|
||||
tell_text = status.tell_state.activity.display_name()
|
||||
|
||||
if status.tell_state.activity.value == "error":
|
||||
tell_color = "red"
|
||||
elif status.tell_state.activity.value in {"mounting", "unmounting", "drying", "cooling"}:
|
||||
tell_color = "orange"
|
||||
else:
|
||||
tell_color = "green"
|
||||
|
||||
self.tell_state_label.setText(f"Tell: {tell_text} ")
|
||||
self.tell_state_label.setStyleSheet(f"color: {tell_color};")
|
||||
|
||||
if status.busy:
|
||||
busy_flag = """ <span style="color: red; "> Busy 🔒 </span>"""
|
||||
else:
|
||||
busy_flag = """ <span style="color: green ; "> Idle 🔓 </span>"""
|
||||
|
||||
html_content = f"""Beamline: {busy_flag} """
|
||||
|
||||
self.busy_label.setText(html_content)
|
||||
|
||||
session_flag = ""
|
||||
if status.session.session == SessionsStateEnum.Vacant:
|
||||
session_flag = """<span style="color: yellow ; "> Vacant 🔓 </span>"""
|
||||
elif status.session.session == SessionsStateEnum.OwnedByYou:
|
||||
session_flag = """<span style="color: green ; "> Owned ⬤ </span>"""
|
||||
elif status.session.session == SessionsStateEnum.OwnedByElse:
|
||||
session_flag = """<span style="color: red ; "> Other 🔒 </span>"""
|
||||
elif status.session.session == SessionsStateEnum.PendingYouToElse:
|
||||
session_flag = """<span style="color: orange ; "> Waiting... ⏳ </span>"""
|
||||
elif status.session.session == SessionsStateEnum.PendingElseToYou:
|
||||
session_flag = """<span style="color: cyan ; "> Request! ⚡ </span>"""
|
||||
|
||||
html_content_session = f"""Session: {session_flag}"""
|
||||
self.session_label.setText(html_content_session)
|
||||
except Exception as e:
|
||||
logger.error(f"Error updating DAQ status in status bar: {e}")
|
||||
|
||||
@Slot(BatonStatus)
|
||||
def update_baton_status(self, status: BatonStatus):
|
||||
|
||||
Reference in New Issue
Block a user