From c3dd2aa38ae3d66ccadbc1b2415c10d3f9c71e44 Mon Sep 17 00:00:00 2001 From: appleb_m Date: Wed, 24 Jun 2026 10:01:42 +0200 Subject: [PATCH] BEC: changed the initialisation function in bec_worker.py and how certain PVS are handled: including ring_current backlight_brightness frontlight_brightness and zoom --- src/aare/devices/bec_worker.py | 90 +++++++++++++++------------------- 1 file changed, 39 insertions(+), 51 deletions(-) diff --git a/src/aare/devices/bec_worker.py b/src/aare/devices/bec_worker.py index 4152b382..7611b50c 100644 --- a/src/aare/devices/bec_worker.py +++ b/src/aare/devices/bec_worker.py @@ -57,6 +57,17 @@ class BECClientWorker: def __init__(self, beamline:MXBeamline, name:str = "default"): BEAMLINE = beamline.value.lower() self.beamline = beamline + if self.beamline is MXBeamline.X06DA: + self._beamline_name = "px_iii" + elif self.beamline is MXBeamline.X10SA: + self._beamline_name = "px_ii" + elif self.beamline is MXBeamline.X06DA: + self._beamline_name = "px_i" + elif self.beamline is MXBeamline.SIMULATED: + self._beamline_name = "SIMULATED" + else: + raise ValueError(f"Unknown beamline: {beamline}") + if self.beamline is MXBeamline.SIMULATED: self.simulated = True @@ -80,23 +91,34 @@ class BECClientWorker: self.helper = FrontendProcedureHelper(self.client.connector) self.__set_scilog_tags() try: - self.position_devices, self.planner = self.__init_beamline_environment() - self.__backlight_brightness = self.position_devices['bl_bright'] - self.__frontlight_brightness = self.position_devices['fl_bright'] + self.__init_beamline_environment() except Exception as e: logger.error(f"Error initialising BEC devices: {e}") #raise self._raise_bec_error(e, operation="create planner") - self.planner = None self.simulated = True - self.__zoom = self.dev.scam_zoom - self.ring_current = self.dev.sls_current.get() logger.debug(f"simulated is {self.simulated}") def __init_beamline_environment(self): try: - return init_beamline_environment() + self.position_devices, self.planner = init_beamline_environment() + self.__backlight_brightness = self.position_devices['bl_bright'] + self.__frontlight_brightness = self.position_devices['fl_bright'] + self.__zoom = self.dev.scam_zoom + self._ring_current = self.dev.sls_current except Exception as e: + logger.error(f"Error initialising planar and position devices: {e}") + self.position_devices = None + self.planner = None + self.__backlight_brightness = None + self.__frontlight_brightness = None + try: + self.__zoom = self.dev.scam_zoom + self._ring_current = self.dev.sls_current + except Exception as e: + logger.error(f"Error initialising zoom and ring_current: {e}") + self.__zoom = None + self.ring_current = None raise Exception(f"Error initialising BEC devices: {e}") def _raise_bec_error(self, exc: Exception, *, operation: str, tags:Optional[List[str]] = None) -> None: @@ -140,30 +162,6 @@ class BECClientWorker: exception=exc, ) from exc - def __get_states(self): - """Get beamline states and modifiers from beamlien_states.yaml""" - if self.simulated: - logger.debug("Simulating initialise_devices") - return None - try: - states, allow_modifiers = get_states() - return states, allow_modifiers - except Exception as e: - self._raise_bec_error(e, operation="initialise beamline states") - - def __planner(self): - if self.simulated is None: - logger.debug("Simulating planner") - return None - self.states, self.allow_modifiers = self.__get_states() - self.deps = planner_deps() - return StateManager( - states=self.states, - deps=self.deps, - devices=self.position_devices, - allow_modifiers=self.allow_modifiers - ) - def __set_scilog_tags(self, tags:Optional[List[str]]=None): try: if tags: @@ -341,26 +339,10 @@ class BECClientWorker: if self.simulated: logger.debug(f"Simulating reinitialise_planner_and_position_devices(method={method})") return [] - - method = str(method or "auto").strip().lower() - try: - if method == "auto": - if self.beamline is MXBeamline.X06DA: - method = "beamline" - else: - method = "sample" - - if method in {"beamline", "sample", "sample_environment"}: - self.position_devices, self.planner = self.__init_beamline_environment() - else: - raise ValueError( - "Invalid BEC reinitialisation method. " - "Expected one of: auto, beamline, sample." - ) - #TODO move these into Init beamline env - self.__backlight_brightness = self.position_devices['bl_bright'] - self.__frontlight_brightness = self.position_devices['fl_bright'] + # self.client.config.update_session_with_file( + # f"/sls/{self.beamline}/config/bec/production/") + self.position_devices, self.planner = self.__init_beamline_environment() logger.info(f"Reinitialised BEC planner and position devices using method={method}") return self.list_position_devices() except Exception as e: @@ -519,6 +501,9 @@ class BECClientWorker: def zoom(self, value:float): self.scans.umv(self.__zoom, value, relative=False) + @property + def ring_current(self) -> float: + return self._ring_current.get() if __name__ == "__main__": import time @@ -542,6 +527,9 @@ if __name__ == "__main__": # print(client.client.show_last_alarm()) # print(client._raise_bec_error(exc=Exception("test"), operation="test", tags=["test"])) print(client.ring_current) + for i in range(10): + print(client._ring_current.get()) + time.sleep(1) # print('setting to 5') # client.backlight_brightness = 5 # print(client.get_backlight_pos()) @@ -572,7 +560,7 @@ if __name__ == "__main__": except Exception as e: #client._raise_bec_error(e, operation="send message") client.shutdown_client() - #print(f"Error: {e}") + print(f"Error: {e}") # try: # det_value = 980