stDAQ seems to work ok

This commit is contained in:
gac-x05la
2025-01-14 14:58:04 +01:00
parent 654ee65833
commit d44073b937

View File

@@ -38,8 +38,6 @@ class StdDaqMixin(CustomDeviceMixin):
d = {} d = {}
if 'kwargs' in self.parent.scaninfo.scan_msg.info: if 'kwargs' in self.parent.scaninfo.scan_msg.info:
scanargs = self.parent.scaninfo.scan_msg.info['kwargs'] scanargs = self.parent.scaninfo.scan_msg.info['kwargs']
print('kwargs')
print(scanargs)
if 'image_width' in scanargs and scanargs['image_width'] != None: if 'image_width' in scanargs and scanargs['image_width'] != None:
d['image_width'] = scanargs['image_width'] d['image_width'] = scanargs['image_width']
if 'image_height' in scanargs and scanargs['image_height'] != None: if 'image_height' in scanargs and scanargs['image_height'] != None:
@@ -49,8 +47,6 @@ class StdDaqMixin(CustomDeviceMixin):
if 'file_path' in scanargs and scanargs['file_path']!=None: if 'file_path' in scanargs and scanargs['file_path']!=None:
self.parent.file_path.set(scanargs['file_path']).wait() self.parent.file_path.set(scanargs['file_path']).wait()
if "daq_num_points" in scanargs: if "daq_num_points" in scanargs:
d["num_points_total"] = scanargs["daq_num_points"] d["num_points_total"] = scanargs["daq_num_points"]
else: else:
@@ -74,12 +70,8 @@ class StdDaqMixin(CustomDeviceMixin):
print('Reconfiguring') print('Reconfiguring')
# Stop if current status is not idle # Stop if current status is not idle
if self.parent.state() != "idle": if self.parent.state() != "idle":
# self.parent.surestop()
self.parent.blueunstage() self.parent.blueunstage()
print(self.parent.state())
print(self.parent.state())
print(self.parent.state())
# Configure new run (will restart the stdDAQ) # Configure new run (will restart the stdDAQ)
logger.warning(f"[{self.parent.name}] Configuring with:\n{d}") logger.warning(f"[{self.parent.name}] Configuring with:\n{d}")
self.parent.configure(d=d) self.parent.configure(d=d)
@@ -94,17 +86,13 @@ class StdDaqMixin(CustomDeviceMixin):
""" Stop a running acquisition and close connection """ Stop a running acquisition and close connection
""" """
self.parent.create_virtual_dataset() self.parent.create_virtual_dataset()
# self.parent.surestop()
self.parent.blueunstage() self.parent.blueunstage()
def on_stop(self): def on_stop(self):
""" Stop a running acquisition and close connection """ Stop a running acquisition and close connection
""" """
# self.parent.surestop()
self.parent.blueunstage() self.parent.blueunstage()
def poll(self) -> None: def poll(self) -> None:
""" Monitor status messages while connection is open. This will block the reply monitoring """ Monitor status messages while connection is open. This will block the reply monitoring
to calling unstage() might throw. Status updates are sent every 1 seconds, but finishing to calling unstage() might throw. Status updates are sent every 1 seconds, but finishing
@@ -330,12 +318,18 @@ class StdDaqClient(PSIDeviceBase):
print(cfg) print(cfg)
def bluestage(self): def bluestage(self):
""" Stages the stdDAQ
Opens a new connection to the stdDAQ, sends the start command with
the current configuration. It waits for the first reply and checks
it for obvious failures.
"""
file_path = self.file_path.get() file_path = self.file_path.get()
num_images = self.num_images.get() num_images = self.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 ii = 0
while True: while ii<5:
self.connect() self.connect()
reply = self.message(message) reply = self.message(message)
@@ -343,44 +337,55 @@ class StdDaqClient(PSIDeviceBase):
reply = json.loads(reply) reply = json.loads(reply)
self.status.set(reply["status"], force=True).wait() self.status.set(reply["status"], force=True).wait()
logger.info(f"[{self.name}] Start DAQ reply: {reply}") logger.info(f"[{self.name}] Start DAQ reply: {reply}")
# Give it more time to reconfigure # Give it more time to reconfigure
if reply["status"] in ("rejected"): if reply["status"] in ("rejected"):
# FIXME: running exposure is a nogo # FIXME: running exposure is a nogo
if reply['reason'] == "gerhtrhjfjf": if reply['reason'] == "driver is busy!":
raise RuntimeError(f"[{self.name}] Start StdDAQ command rejected: already running") raise RuntimeError(f"[{self.name}] Start stdDAQ command rejected: already running")
else: else:
# Give it more time to restart # Give it more time to consolidate
sleep(2) sleep(1)
else: else:
break # Success!!!
print(f"[{self.name}] Started stdDAQ on try {ii} in: {reply['status']}")
return
ii += 1 ii += 1
if ii == 5: raise RuntimeError(f"[{self.name}] Failed to start the stdDAQ in 5 tries, reason: {reply['reason']}")
break
if reply is not None and reply["status"] in ("rejected"):
raise RuntimeError(
f"Start StdDAQ command rejected (might be already running): {reply['reason']}"
)
def blueunstage(self): def blueunstage(self):
""" Unstages the DAQ from a new connection""" """ Unstages the stdDAQ
Opens a new connection to the stdDAQ, sends the stop command and
waits for the idle state.
"""
ii = 0 ii = 0
while True: while ii<10:
# Stop the DAQ (will close connection) - reply is always "success"
self.connect() self.connect()
self.message({"command": "stop_all"}, wait_reply=False) self.message({"command": "stop_all"}, wait_reply=False)
# Reply is always "success"
# Let it consolidate
sleep(0.2)
# Check final status (from new connection)
self.connect() self.connect()
reply = self.message({"command": "status"}) reply = self.message({"command": "status"})
if reply is not None: if reply is not None:
logger.info(f"[{self.name}] DAQ status reply: {reply}") logger.info(f"[{self.name}] DAQ status reply: {reply}")
reply = json.loads(reply) reply = json.loads(reply)
# Give it more time to reconfigure
if reply["status"] in ("idle") or ii >= 5: if reply["status"] in ("idle"):
break # Only 'idle' state accepted
print(f"DAQ stopped on try {ii}")
return
elif reply["status"] in ("stop"):
# Give it more time to stop
sleep(0.5)
elif ii >= 6:
raise RuntimeError(f"Failed to stop StdDAQ: {reply}")
ii += 1 ii += 1
if reply is not None and reply["status"] not in ("idle"): raise RuntimeError(f"Failed to stop StdDAQ in time")
raise RuntimeError(f"Failed to stop StdDAQ: {reply}")
def get_daq_config(self) -> dict: def get_daq_config(self) -> dict:
"""Read the current configuration from the DAQ """Read the current configuration from the DAQ
@@ -442,12 +447,16 @@ class StdDaqClient(PSIDeviceBase):
def state(self) -> str | None: def state(self) -> str | None:
""" Querry the current system state""" """ Querry the current system state"""
r = self.message({'command': 'status'}, wait_reply=True) try:
if r is None: logger.debug(f"[{self.name}] Connecting to {self.ws_url.get()}")
return None _wsclient = connect(self.ws_url.get())
else: msg = json.dumps({'command': 'status'})
_wsclient.send(msg)
r = _wsclient.recv(timeout=1)
r = json.loads(r) r = json.loads(r)
return r['status'] return r['status']
except ConnectionRefusedError:
raise
def surestop(self, timeout=5): def surestop(self, timeout=5):
""" Stops a running acquisition """ Stops a running acquisition