stDAQ seems to work ok
This commit is contained in:
@@ -38,8 +38,6 @@ 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:
|
||||
@@ -49,8 +47,6 @@ class StdDaqMixin(CustomDeviceMixin):
|
||||
if 'file_path' in scanargs and scanargs['file_path']!=None:
|
||||
self.parent.file_path.set(scanargs['file_path']).wait()
|
||||
|
||||
|
||||
|
||||
if "daq_num_points" in scanargs:
|
||||
d["num_points_total"] = scanargs["daq_num_points"]
|
||||
else:
|
||||
@@ -74,12 +70,8 @@ class StdDaqMixin(CustomDeviceMixin):
|
||||
print('Reconfiguring')
|
||||
# Stop if current status is not idle
|
||||
if self.parent.state() != "idle":
|
||||
# self.parent.surestop()
|
||||
self.parent.blueunstage()
|
||||
|
||||
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)
|
||||
@@ -94,17 +86,13 @@ class StdDaqMixin(CustomDeviceMixin):
|
||||
""" Stop a running acquisition and close connection
|
||||
"""
|
||||
self.parent.create_virtual_dataset()
|
||||
# self.parent.surestop()
|
||||
self.parent.blueunstage()
|
||||
|
||||
|
||||
def on_stop(self):
|
||||
""" Stop a running acquisition and close connection
|
||||
"""
|
||||
# self.parent.surestop()
|
||||
self.parent.blueunstage()
|
||||
|
||||
|
||||
def poll(self) -> None:
|
||||
""" 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
|
||||
@@ -330,12 +318,18 @@ class StdDaqClient(PSIDeviceBase):
|
||||
print(cfg)
|
||||
|
||||
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()
|
||||
num_images = self.num_images.get()
|
||||
message = {"command": "start", "path": file_path, "n_image": num_images, }
|
||||
|
||||
ii = 0
|
||||
while True:
|
||||
while ii<5:
|
||||
self.connect()
|
||||
reply = self.message(message)
|
||||
|
||||
@@ -343,44 +337,55 @@ class StdDaqClient(PSIDeviceBase):
|
||||
reply = json.loads(reply)
|
||||
self.status.set(reply["status"], force=True).wait()
|
||||
logger.info(f"[{self.name}] Start DAQ reply: {reply}")
|
||||
|
||||
# Give it more time to reconfigure
|
||||
if reply["status"] in ("rejected"):
|
||||
# FIXME: running exposure is a nogo
|
||||
if reply['reason'] == "gerhtrhjfjf":
|
||||
raise RuntimeError(f"[{self.name}] Start StdDAQ command rejected: already running")
|
||||
if reply['reason'] == "driver is busy!":
|
||||
raise RuntimeError(f"[{self.name}] Start stdDAQ command rejected: already running")
|
||||
else:
|
||||
# Give it more time to restart
|
||||
sleep(2)
|
||||
# Give it more time to consolidate
|
||||
sleep(1)
|
||||
else:
|
||||
break
|
||||
# Success!!!
|
||||
print(f"[{self.name}] Started stdDAQ on try {ii} in: {reply['status']}")
|
||||
return
|
||||
ii += 1
|
||||
if ii == 5:
|
||||
break
|
||||
if reply is not None and reply["status"] in ("rejected"):
|
||||
raise RuntimeError(
|
||||
f"Start StdDAQ command rejected (might be already running): {reply['reason']}"
|
||||
)
|
||||
|
||||
raise RuntimeError(f"[{self.name}] Failed to start the stdDAQ in 5 tries, reason: {reply['reason']}")
|
||||
|
||||
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
|
||||
while True:
|
||||
while ii<10:
|
||||
# Stop the DAQ (will close connection) - reply is always "success"
|
||||
self.connect()
|
||||
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()
|
||||
reply = self.message({"command": "status"})
|
||||
if reply is not None:
|
||||
logger.info(f"[{self.name}] DAQ status reply: {reply}")
|
||||
reply = json.loads(reply)
|
||||
# Give it more time to reconfigure
|
||||
if reply["status"] in ("idle") or ii >= 5:
|
||||
break
|
||||
|
||||
if reply["status"] in ("idle"):
|
||||
# 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
|
||||
if reply is not None and reply["status"] not in ("idle"):
|
||||
raise RuntimeError(f"Failed to stop StdDAQ: {reply}")
|
||||
raise RuntimeError(f"Failed to stop StdDAQ in time")
|
||||
|
||||
def get_daq_config(self) -> dict:
|
||||
"""Read the current configuration from the DAQ
|
||||
@@ -442,12 +447,16 @@ class StdDaqClient(PSIDeviceBase):
|
||||
|
||||
def state(self) -> str | None:
|
||||
""" Querry the current system state"""
|
||||
r = self.message({'command': 'status'}, wait_reply=True)
|
||||
if r is None:
|
||||
return None
|
||||
else:
|
||||
try:
|
||||
logger.debug(f"[{self.name}] Connecting to {self.ws_url.get()}")
|
||||
_wsclient = connect(self.ws_url.get())
|
||||
msg = json.dumps({'command': 'status'})
|
||||
_wsclient.send(msg)
|
||||
r = _wsclient.recv(timeout=1)
|
||||
r = json.loads(r)
|
||||
return r['status']
|
||||
except ConnectionRefusedError:
|
||||
raise
|
||||
|
||||
def surestop(self, timeout=5):
|
||||
""" Stops a running acquisition
|
||||
|
||||
Reference in New Issue
Block a user