wip fixing jfj client, improve start procedure
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
""" Module with client interface for the Jungfrau Joch detector API"""
|
||||
"""Module with client interface for the Jungfrau Joch detector API"""
|
||||
|
||||
import enum
|
||||
import math
|
||||
@@ -6,11 +6,11 @@ import math
|
||||
from bec_lib.logger import bec_logger
|
||||
from jfjoch_client.api.default_api import DefaultApi
|
||||
from jfjoch_client.api_client import ApiClient
|
||||
from jfjoch_client.api_response import ApiResponse
|
||||
from jfjoch_client.configuration import Configuration
|
||||
from jfjoch_client.models.broker_status import BrokerStatus
|
||||
from jfjoch_client.models.dataset_settings import DatasetSettings
|
||||
from jfjoch_client.models.detector_settings import DetectorSettings
|
||||
from jfjoch_client.api_response import ApiResponse
|
||||
from ophyd import Device
|
||||
|
||||
logger = bec_logger.logger
|
||||
@@ -40,8 +40,10 @@ class ResponseWaitDone(int, enum.Enum):
|
||||
DETECTOR_INACTIVE = 502
|
||||
TIMEOUT_REACHED = 504
|
||||
|
||||
|
||||
class ResponseCancelDone(int, enum.Enum):
|
||||
""" HTTP Response for cancel post"""
|
||||
"""HTTP Response for cancel post"""
|
||||
|
||||
CANCEL_SENT_TO_FPGA = 200
|
||||
|
||||
|
||||
@@ -83,7 +85,7 @@ class JungfrauJochClient:
|
||||
if status != DetectorState.IDLE:
|
||||
self.api.initialize_post()
|
||||
self.wait_till_done(timeout) # Blocking call
|
||||
self.initialised = True
|
||||
self.initialised = True
|
||||
|
||||
def set_detector_settings(self, settings: dict | DetectorSettings) -> None:
|
||||
"""Set the detector settings. JungfrauJoch must be in IDLE, Error or Inactive state.
|
||||
@@ -121,7 +123,7 @@ class JungfrauJochClient:
|
||||
if isinstance(settings, dict):
|
||||
settings = DatasetSettings(**settings)
|
||||
try:
|
||||
res:ApiResponse = self.api.start_post_with_http_info(dataset_settings=settings)
|
||||
res: ApiResponse = self.api.start_post_with_http_info(dataset_settings=settings)
|
||||
if res.status_code != 200:
|
||||
response = f"Error in {self._parent_name}, while setting measurement settings {settings}, response: {res}"
|
||||
raise JungfrauJochClientError(response)
|
||||
@@ -132,21 +134,18 @@ class JungfrauJochClient:
|
||||
response = f"Error in {self._parent_name}, while setting measurement settings {settings}, exception: {e}"
|
||||
logger.error(response)
|
||||
raise JungfrauJochClientError(response) from e
|
||||
|
||||
|
||||
def stop(self) -> None:
|
||||
"""Stop the acquisition"""
|
||||
try:
|
||||
res:ApiResponse = self.api.cancel_post_with_http_info() # Should we use a timeout?
|
||||
res: ApiResponse = self.api.cancel_post_with_http_info() # Should we use a timeout?
|
||||
if res.status_code != ResponseCancelDone.CANCEL_SENT_TO_FPGA:
|
||||
response = f"Error in device {self._parent_name} while stopping the measurement. Exception: {exc}"
|
||||
response = f"Error in device {self._parent_name} while stopping the measurement. API Response: {res}"
|
||||
raise JungfrauJochClientError(response)
|
||||
except JungfrauJochClientError as e:
|
||||
raise e
|
||||
except Exception as exc:
|
||||
logger.error(f"")
|
||||
logger.error(response)
|
||||
raise(JungfrauJochClientError(response)) from exc
|
||||
|
||||
|
||||
|
||||
raise JungfrauJochClientError from exc
|
||||
|
||||
def wait_till_done(self, timeout: int = 5) -> None:
|
||||
"""Wait for JungfrauJoch to be in Idle state. Blocking call with timeout.
|
||||
|
||||
Reference in New Issue
Block a user