WIP: Still problems to get the stddaq to work according to configuration

This commit is contained in:
gac-x05la
2025-01-08 17:01:44 +01:00
parent 457e5c9a5b
commit 39ba19ddb2
2 changed files with 55 additions and 21 deletions

View File

@@ -38,10 +38,14 @@ class StdDaqMixin(CustomDeviceMixin):
d = {}
if 'kwargs' in self.parent.scaninfo.scan_msg.info:
scanargs = self.parent.scaninfo.scan_msg.info['kwargs']
print('kwargs')
print(scanargs)
if 'image_width' in scanargs and scanargs['image_width'] != None:
d['image_width'] = scanargs['image_width']
if 'image_height' in scanargs and scanargs['image_height'] != None:
d['image_height'] = scanargs['image_height']
if 'nr_writers' in scanargs and scanargs['nr_writers'] != None:
d['nr_writers'] = scanargs['nr_writers']
if 'file_path' in scanargs and scanargs['file_path']!=None:
self.parent.file_path.set(scanargs['file_path']).wait()
@@ -67,9 +71,13 @@ class StdDaqMixin(CustomDeviceMixin):
# Perform bluesky-style configuration
if len(d) > 0:
print('Reconfiguring')
# Stop if current status is not idle
if self.parent.state() != "idle":
self.parent.surestop()
print(self.parent.state())
print(self.parent.state())
print(self.parent.state())
# Configure new run (will restart the stdDAQ)
logger.warning(f"[{self.parent.name}] Configuring with:\n{d}")
self.parent.configure(d=d)
@@ -77,7 +85,7 @@ class StdDaqMixin(CustomDeviceMixin):
# Try to start a new run
file_path = self.parent.file_path.get()
num_images = self.parent.num_images.get()
message = {"command": "start", "path": file_path, "n_image": num_images}
message = {"command": "start", "path": file_path, "n_image": num_images, }
ii = 0
while True:
self.parent.connect()
@@ -111,6 +119,7 @@ class StdDaqMixin(CustomDeviceMixin):
def on_unstage(self):
""" Stop a running acquisition and close connection
"""
self.parent.create_virtual_dataset()
self.parent.surestop()
def on_stop(self):
@@ -295,6 +304,7 @@ class StdDaqClient(PSIDeviceBase):
* 4: Invert pixel values, but do not apply any linearity correction
* 5: Apply the full linearity correction
"""
print('This is d')
print(d)
if 'image_width' in d and d['image_width']!=None:
self.cfg_pixel_width.set(d['image_width']).wait()
@@ -302,31 +312,45 @@ class StdDaqClient(PSIDeviceBase):
self.cfg_pixel_height.set(d['image_height']).wait()
if 'num_points_total' in d:
self.num_images.set(d['num_points_total']).wait()
if 'file_path' in d and d['file_path']!=None:
self.file_path.set(d['file_path']).wait()
if 'nr_writers' in d and d['nr_writers']!=None:
print('Setting number of writers ' + str(d['nr_writers']))
self.cfg_nr_writers.set(d['nr_writers']).wait()
# Restart the DAQ if resolution changed
cfg = self.get_daq_config()
if cfg['image_pixel_height'] != self.cfg_pixel_height.get() or
cfg['image_pixel_width'] != self.cfg_pixel_width.get() or
cfg['bit_depth'] != self.cfg_bit_depth.get() or
print(cfg)
print(cfg['number_of_writers'])
print(self.cfg_nr_writers.get())
if cfg['image_pixel_height'] != self.cfg_pixel_height.get() or \
cfg['image_pixel_width'] != self.cfg_pixel_width.get() or \
cfg['bit_depth'] != self.cfg_bit_depth.get() or \
cfg['number_of_writers'] != self.cfg_nr_writers.get():
# Stop if current status is not idle
if self.state() != "idle":
status = self.state()
print(status)
# if self.state() != "idle":
if status != "idle":
self.surestop()
status = self.state()
print(status)
# Stop running acquisition
print('Before unstage')
self.unstage()
print('After unstage')
# Update retrieved config
cfg['image_pixel_height'] = int(self.cfg_pixel_height.get())
cfg['image_pixel_width'] = int(self.cfg_pixel_width.get())
cfg['bit_depth'] = int(self.cfg_bit_depth.get())
cfg['number_of_writers'] = int(self.cfg_nr_writers.get())
self.set_daq_config(cfg)
self.read_daq_config()
print(cfg)
r = self.set_daq_config(cfg)
print(r)
cfg=self.read_daq_config()
print(cfg)
def get_daq_config(self) -> dict:
"""Read the current configuration from the DAQ
@@ -372,10 +396,10 @@ class StdDaqClient(PSIDeviceBase):
"""
url = self.rest_url.get() + '/api/h5/create_interleaved_vds'
r = requests.pos(
r = requests.post(
url,
params = {'user': 'ioc'},
data = {'base_path': self.file_path. 'output_file': 'fede_virtual_test'},
data = {'base_path': self.file_path, 'output_file': 'fede_virtual_test'},
timeout = 2,
headers = {'Content-type': 'application/json'}
)
@@ -419,7 +443,8 @@ class StdDaqClient(PSIDeviceBase):
reply = client.recv(timeout=1)
reply = json.loads(reply)
if reply['status'] in ['idle', 'stoped']:
print(reply['status'])
if reply['status'] in ['idle', 'stoped']:
logger.warning(f"[{self.name}] Stop-all command finished in {reply['status']}")
return

View File

@@ -85,8 +85,8 @@ class Measurement:
self.build_filename()
def acquire_darks(self,nimages_dark, exposure_time=None, exposure_period=None, roix=None, roiy=None, acq_mode=None,
file_path=None):
def acquire_darks(self,nimages_dark, exposure_time=None, exposure_period=None,
roix=None, roiy=None, acq_mode=None, file_path=None):
"""
Acquire a set of dark images with shutters closed.
@@ -111,11 +111,11 @@ class Measurement:
--------
fede_darks(100, exposure_time=5)
"""
dev.es1_tasks.enabled = False
dev.es1_psod.enabled = False
dev.es1_ddaq.enabled = False
dev.es1_ismc.enabled = False
dev.es1_roty.enabled = False
# dev.es1_tasks.enabled = False
# dev.es1_psod.enabled = False
# dev.es1_ddaq.enabled = False
# dev.es1_ismc.enabled = False
# dev.es1_roty.enabled = False
dev.gfcam.enabled = True
dev.gfdaq.enabled = True
dev.daq_stream0.enabled = True
@@ -142,6 +142,15 @@ class Measurement:
# Commit changes to GF
dev.gfcam.cmdSetParam.set(1).wait()
if exposure_time != None:
self.exposure_time = exposure_time
if exposure_period != None:
self.exposure_period = exposure_period
if roix != None:
self.roix = roix
if roiy != None:
self.roiy = roiy
if file_path!=None:
if os.path.isdir(file_path):
pass
@@ -150,5 +159,5 @@ class Measurement:
### TODO: camera reset
print("Handing over to 'scans.acquire_dark")
scans.acquire_dark(exp_burst=nimages_dark, exp_time=exposure_time, exp_period=exposure_period, image_width=roix,
image_height=roiy, acq_mode=acq_mode, file_path=file_path, nr_writers=1)
scans.acquire_dark(exp_burst=nimages_dark, exp_time=self.exposure_time, exp_period=self.exposure_period, image_width=self.roix,
image_height=self.roiy, acq_mode=acq_mode, file_path=file_path, nr_writers=1)