Bluesky-like parameter passing

This commit is contained in:
gac-x05la
2024-07-26 15:25:50 +02:00
committed by mohacsi_i
parent da823f0a40
commit 6e98d5789c
5 changed files with 85 additions and 49 deletions

View File

@@ -114,6 +114,8 @@ gfclient:
prefix: 'X02DA-CAM-GF2:'
backend_url: 'http://xbl-daq-28:8080'
auto_soft_enable: true
daq_ws_url: 'ws://xbl-daq-29:8080'
daq_rest_url: 'http://xbl-daq-29:5000'
deviceTags:
- camera
enabled: true
@@ -126,7 +128,8 @@ daq:
description: Standard DAQ controls
deviceClass: tomcat_bec.devices.gigafrost.stddaq_ws.StdDaqWsClient
deviceConfig:
url: 'ws://xbl-daq-29:8080'
ws_url: 'ws://xbl-daq-29:8080'
rest_url: 'http://xbl-daq-29:5000'
deviceTags:
- std-daq
enabled: true
@@ -137,9 +140,9 @@ daq:
daqcfg:
description: Standard DAQ config
deviceClass: tomcat_bec.devices.gigafrost.stddaq_rest.StdDaqRestConfig
deviceClass: tomcat_bec.devices.gigafrost.stddaq_rest.StdDaqRestClient
deviceConfig:
url: 'http://xbl-daq-29:5000'
rest_url: 'http://xbl-daq-29:5000'
deviceTags:
- std-daq
enabled: true

View File

@@ -411,21 +411,11 @@ class GigaFrostCamera(PSIDetectorBase):
self.state.put(const.GfStatus.NEW, force=True)
return super()._init()
def configure(
self,
d: dict=None,
nimages=10,
exposure=0.2,
period=1.0,
roix=2016,
roiy=2016,
scanid=0,
correction_mode=5,
):
def configure(self, d: dict=None):
"""Configure the next scan with the GigaFRoST camera
Parameters
----------
Parameters as 'd' dictionary
----------------------------
nimages : int, optional
Number of images to be taken during each scan. Set to -1 for an
unlimited number of images (limited by the ringbuffer size and
@@ -434,9 +424,9 @@ class GigaFrostCamera(PSIDetectorBase):
Exposure time [ms]. (default = 0.2)
period : float, optional
Exposure period [ms], ignored in soft trigger mode. (default = 1.0)
roix : int, optional
pixel_width : int, optional
ROI size in the x-direction [pixels] (default = 2016)
roiy : int, optional
pixel_height : int, optional
ROI size in the y-direction [pixels] (default = 2016)
scanid : int, optional
Scan identification number to be associated with the scan data
@@ -455,14 +445,19 @@ class GigaFrostCamera(PSIDetectorBase):
# If Bluesky style configure
if d is not None:
nimages = d.get('nimages', 10)
exposure = d.get('exposure', exposure)
period = d.get('period', period)
roix = d.get('roix', roix)
roiy = d.get('roiy', roiy)
scanid = d.get('scanid', scanid)
correction_mode = d.get('correction_mode', correction_mode)
exposure = d.get('exposure', 0.2)
period = d.get('period', 1.0)
pixel_width = d.get('pixel_width', 2016)
pixel_height = d.get('pixel_height', 2016)
pixel_width = d.get('image_width', pixel_width)
pixel_height = d.get('image_height', pixel_height)
pixel_width = d.get('roix', pixel_width)
pixel_height = d.get('roiy', pixel_height)
scanid = d.get('scanid', 0)
correction_mode = d.get('correction_mode', 5)
# Stop acquisition
self.unstage()
self.cmdStartCamera.set(0).wait()
if self.autoSoftEnable.get():
self.cmdSoftEnable.set(0).wait()
@@ -470,8 +465,8 @@ class GigaFrostCamera(PSIDetectorBase):
# change settings
self.cfgExposure.set(exposure).wait()
self.cfgFramerate.set(period).wait()
self.cfgRoiX.set(roix).wait()
self.cfgRoiY.set(roiy).wait()
self.cfgRoiX.set(pixel_width).wait()
self.cfgRoiY.set(pixel_height).wait()
self.cfgScanId.set(scanid).wait()
self.cfgCntNum.set(nimages).wait()
self.cfgCorrMode.set(correction_mode).wait()

View File

@@ -308,8 +308,8 @@ class GigaFrostClient(PSIDetectorBase):
px_daq_h = self.daq.cfg.cfg_image_pixel_height.get()
px_daq_w = self.daq.cfg.cfg_image_pixel_width.get()
px_gf_h = self.cam.cfgRoiX.get()
px_gf_w = self.cam.cfgRoiY.get()
px_gf_w = self.cam.cfgRoiX.get()
px_gf_h = self.cam.cfgRoiY.get()
if px_daq_h != px_gf_h or px_daq_w != px_gf_w:
raise RuntimeError(f"Different image size configured on GF and the DAQ")

View File

@@ -67,22 +67,16 @@ class StdDaqRestClient(Device):
self.cfg_image_pixel_width.set(cfg['image_pixel_width']).wait()
self.cfg_start_udp_port.set(cfg['start_udp_port']).wait()
self.cfg_writer_user_id.set(cfg['writer_user_id']).wait()
self.cfg_submodule_info.set(cfg['submodule_info']).wait()
#self.cfg_submodule_info.set(cfg['submodule_info']).wait()
self.cfg_max_number_of_forwarders_spawned.set(cfg['max_number_of_forwarders_spawned']).wait()
self.cfg_use_all_forwarders.set(cfg['use_all_forwarders']).wait()
self.cfg_module_sync_queue_size.set(cfg['module_sync_queue_size']).wait()
self.cfg_module_positions.set(cfg['module_positions']).wait()
#self.cfg_module_positions.set(cfg['module_positions']).wait()
self._config_read = True
return cfg
def write_daq_config(self):
"""Write configuration ased on current PV values. Some fields might be
unchangeable.
"""
if not self._config_read:
raise RuntimeError("Pleae read config before editing")
return r
def _build_config(self):
config = {
'detector_name': str(self.cfg_detector_name.get()),
'detector_type': str(self.cfg_detector_type.get()),
@@ -92,21 +86,64 @@ class StdDaqRestClient(Device):
'image_pixel_width': int(self.cfg_image_pixel_width.get()),
'start_udp_port': int(self.cfg_start_udp_port.get()),
'writer_user_id': int(self.cfg_writer_user_id.get()),
'submodule_info': self.cfg_submodule_info.get(),
'submodule_info': {},
'max_number_of_forwarders_spawned': int(self.cfg_max_number_of_forwarders_spawned.get()),
'use_all_forwarders': bool(self.cfg_use_all_forwarders.get()),
'module_sync_queue_size': int(self.cfg_module_sync_queue_size.get()),
'module_positions': self.cfg_module_positions.get()
'module_positions': {}
}
return config
def write_daq_config(self):
"""Write configuration ased on current PV values. Some fields might be
unchangeable.
"""
if not self._config_read:
raise RuntimeError("Pleae read config before editing")
config = self._build_config()
params = {"user": "ioc", "config_file": "/etc/std_daq/configs/gf1.json"}
r = requests.post(self._url_base +'/api/config/set', params=params, json=config, headers={"Content-Type": "application/json"})
if r.status_code != 200:
raise ConnectionError(f"[{self.name}] Error {r.status_code}:\t{r.text}")
return r
def configure(self, d: dict=None):
"""Configure the next scan with the GigaFRoST camera
Parameters
----------
pixel_width : int, optional
Image size in the x-direction [pixels] (default = 2016)
pixel_height : int, optional
Image size in the y-direction [pixels] (default = 2016)
"""
old = self.read_configuration()
# If Bluesky style configure
if d is not None:
# Only reconfigure if we're instructed
if ('pixel_width' in d) or ('pixel_height' in d) or ('image_width' in d) or ('image_height' in d):
pixel_width = d.get('pixel_width', 2016)
pixel_height = d.get('pixel_height', 2016)
pixel_width = d.get('image_width', pixel_width)
pixel_height = d.get('image_height', pixel_height)
self.cfg_image_pixel_height.set(pixel_height).wait()
self.cfg_image_pixel_width.set(pixel_width).wait()
self.write_daq_config()
new = self.read_configuration()
return old, new
def read(self):
self.read_daq_config()
return super().read()
def stage(self) -> list:
"""Stage op: Read the current configuration from the DAQ

View File

@@ -84,7 +84,7 @@ class StdDaqWsClient(Device):
self._mon = Thread(target=self.poll, daemon=True)
self._mon.start()
def configure(self, d: dict=None, n_total: int = None, file_path: str = None) -> tuple:
def configure(self, d: dict={}) -> tuple:
"""Set the standard DAQ parameters for the next run
Note that full reconfiguration is not possible with the websocket
@@ -106,15 +106,16 @@ class StdDaqWsClient(Device):
"""
old_config = self.read_configuration()
# If Bluesky style configure
if d is not None:
n_total = d.get('n_total', None)
file_path = d.get('file_path', None)
if n_total is not None:
self.n_total.set(int(n_total))
if file_path is not None:
self.output_file.set(str(file_path))
if d is not None:
# Set acquisition parameters
if 'n_total' in d:
self.n_total.set(int(d['n_total']))
if 'file_path' in d:
self.output_file.set(str(d['file_path']))
# Configure DAQ
if 'pixel_width' in d or 'pixel_height' in d:
self.cfg.configure(d)
new_config = self.read_configuration()
return (old_config, new_config)