Closer to proper stopping
This commit is contained in:
@@ -83,35 +83,7 @@ class StdDaqMixin(CustomDeviceMixin):
|
||||
self.parent.configure(d=d)
|
||||
|
||||
# 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, }
|
||||
ii = 0
|
||||
while True:
|
||||
self.parent.connect()
|
||||
reply = self.parent.message(message)
|
||||
|
||||
if reply is not None:
|
||||
reply = json.loads(reply)
|
||||
self.parent.status.set(reply["status"], force=True).wait()
|
||||
logger.info(f"[{self.parent.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.parent.name}] Start StdDAQ command rejected: already running")
|
||||
else:
|
||||
# Give it more time to restart
|
||||
sleep(2)
|
||||
else:
|
||||
break
|
||||
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']}"
|
||||
)
|
||||
self.parent.bluestage()
|
||||
# And start status monitoring
|
||||
self._mon = Thread(target=self.poll, daemon=True)
|
||||
self._mon.start()
|
||||
@@ -165,7 +137,7 @@ class StdDaqClient(PSIDeviceBase):
|
||||
"""
|
||||
# pylint: disable=too-many-instance-attributes
|
||||
custom_prepare_cls = StdDaqMixin
|
||||
USER_ACCESS = ["set_daq_config", "get_daq_config", "surestop", "nuke", "connect", "message", "state"]
|
||||
USER_ACCESS = ["set_daq_config", "get_daq_config", "surestop", "nuke", "connect", "message", "state", "bluestage"]
|
||||
_wsclient = None
|
||||
|
||||
# Status attributes
|
||||
@@ -211,13 +183,6 @@ class StdDaqClient(PSIDeviceBase):
|
||||
except Exception as ex:
|
||||
logger.error(f"Failed to connect to the stdDAQ REST API\n{ex}")
|
||||
|
||||
def __del__(self) -> None:
|
||||
try:
|
||||
self._wsclient.close()
|
||||
except TypeError:
|
||||
pass
|
||||
return super().__del__()
|
||||
|
||||
def connect(self):
|
||||
"""Connect to the StdDAQ's websockets interface
|
||||
|
||||
@@ -352,6 +317,59 @@ class StdDaqClient(PSIDeviceBase):
|
||||
cfg=self.read_daq_config()
|
||||
print(cfg)
|
||||
|
||||
def bluestage(self):
|
||||
|
||||
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:
|
||||
self.connect()
|
||||
reply = self.message(message)
|
||||
|
||||
if reply is not None:
|
||||
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")
|
||||
else:
|
||||
# Give it more time to restart
|
||||
sleep(2)
|
||||
else:
|
||||
break
|
||||
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']}"
|
||||
)
|
||||
|
||||
|
||||
def blueunstage(self):
|
||||
|
||||
ii = 0
|
||||
while True:
|
||||
self.connect()
|
||||
self.message({"command": "stop_all"}, wait_reply=False)
|
||||
# Reply is always "success"
|
||||
|
||||
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
|
||||
ii += 1
|
||||
if reply is not None and reply["status"] not in ("idle"):
|
||||
raise RuntimeError(f"Failed to stop StdDAQ: {reply}")
|
||||
|
||||
def get_daq_config(self) -> dict:
|
||||
"""Read the current configuration from the DAQ
|
||||
"""
|
||||
@@ -461,5 +479,5 @@ class StdDaqClient(PSIDeviceBase):
|
||||
|
||||
# Automatically connect to microXAS testbench if directly invoked
|
||||
if __name__ == "__main__":
|
||||
daq = StdDaqClient(name="daq", ws_url="ws://xbl-daq-29:8080", rest_url="http://xbl-daq-29:5000")
|
||||
daq = StdDaqClient(name="daq", ws_url="ws://sls-daq-001:8080", rest_url="http://sls-daq-001:5000")
|
||||
daq.wait_for_connection()
|
||||
|
||||
Reference in New Issue
Block a user