DAQ staging unstaging works without config
This commit is contained in:
@@ -86,11 +86,11 @@ class AerotechTasksMixin(CustomDeviceMixin):
|
||||
|
||||
def on_unstage(self):
|
||||
"""Stop the currently selected task"""
|
||||
self.switch.set("Stop").wait()
|
||||
self.parent.switch.set("Stop").wait()
|
||||
|
||||
def on_stop(self):
|
||||
"""Stop the currently selected task"""
|
||||
self.switch.set("Stop").wait()
|
||||
self.parent.switch.set("Stop").wait()
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ class GigaFrostClient(PSIDetectorBase):
|
||||
custom_prepare_cls = GigaFrostClientMixin
|
||||
USER_ACCESS = ["kickoff"]
|
||||
|
||||
# cam = Component(gfcam.GigaFrostCamera, prefix="X02DA-CAM-GF2:", name="cam")
|
||||
cam = Component(gfcam.GigaFrostCamera, prefix="X02DA-CAM-GF2:", name="cam")
|
||||
daq = Component(stddaq.StdDaqClient, name="daq")
|
||||
|
||||
# pylint: disable=too-many-arguments
|
||||
@@ -124,8 +124,8 @@ class GigaFrostClient(PSIDetectorBase):
|
||||
kind=None,
|
||||
**kwargs,
|
||||
):
|
||||
# self.__class__.__dict__["cam"].kwargs['backend_url'] = backend_url
|
||||
# self.__class__.__dict__["cam"].kwargs['auto_soft_enable'] = auto_soft_enable
|
||||
self.__class__.__dict__["cam"].kwargs['backend_url'] = backend_url
|
||||
self.__class__.__dict__["cam"].kwargs['auto_soft_enable'] = auto_soft_enable
|
||||
self.__class__.__dict__["daq"].kwargs['ws_url'] = daq_ws_url
|
||||
self.__class__.__dict__["daq"].kwargs['rest_url'] = daq_rest_url
|
||||
|
||||
@@ -172,8 +172,8 @@ class GigaFrostClient(PSIDetectorBase):
|
||||
def stage(self):
|
||||
""" Stages the current device and all sub-devices
|
||||
"""
|
||||
px_daq_h = self.daq.config.cfg_pixel_height.get()
|
||||
px_daq_w = self.daq.config.cfg_pixel_width.get()
|
||||
px_daq_h = self.daq.cfg_pixel_height.get()
|
||||
px_daq_w = self.daq.cfg_pixel_width.get()
|
||||
px_gf_w = self.cam.cfgRoiX.get()
|
||||
px_gf_h = self.cam.cfgRoiY.get()
|
||||
|
||||
|
||||
@@ -34,9 +34,10 @@ class StdDaqMixin(CustomDeviceMixin):
|
||||
|
||||
NOTE: Tomcat might use multiple cameras with their own separate DAQ instances.
|
||||
"""
|
||||
logger.warning(self.parent.scaninfo.__dict__)
|
||||
logger.warning(self.parent.scaninfo.__dict__.keys())
|
||||
|
||||
# Fish out our configuration from scaninfo (via explicit or generic addressing)
|
||||
scaninfo = self.parent.scaninfo
|
||||
prefix = self.parent.parent.name if self.parent.parent is not None else self.parent.name
|
||||
d = {}
|
||||
if hasattr(self.parent.scaninfo, prefix + '_image_width'):
|
||||
@@ -110,17 +111,21 @@ class StdDaqMixin(CustomDeviceMixin):
|
||||
def on_unstage(self) -> None:
|
||||
""" Stop a running acquisition and close connection
|
||||
"""
|
||||
if self.parent._wsclient is None:
|
||||
self.parent.connect()
|
||||
|
||||
try:
|
||||
if self.parent._wsclient is None:
|
||||
self.parent.connect()
|
||||
message = {"command": "stop"}
|
||||
self.parent.message(message, wait_reply=False)
|
||||
except RuntimeError:
|
||||
self.parent.message({"command": "stop"}, wait_reply=False)
|
||||
except (ConnectionClosedOK, ConnectionClosedError):
|
||||
self.parent.connect()
|
||||
self.parent.message({"command": "stop"}, wait_reply=False)
|
||||
except (RuntimeError, TypeError):
|
||||
# The poller thread locks recv raising a RuntimeError
|
||||
pass
|
||||
finally:
|
||||
try:
|
||||
self.parent._wsclient.close()
|
||||
logger.debug(f"[{self.parent.name}] Closing socket after unstage")
|
||||
self.parent._wsclient = None
|
||||
except TypeError:
|
||||
# Already closed
|
||||
pass
|
||||
@@ -140,6 +145,8 @@ class StdDaqMixin(CustomDeviceMixin):
|
||||
for msg in self.parent._wsclient:
|
||||
message = json.loads(msg)
|
||||
self.parent.status.put(message["status"], force=True)
|
||||
logger.warning(f"[{self.parent.name}] {message['status']}")
|
||||
|
||||
except (ConnectionClosedError, ConnectionClosedOK, AssertionError):
|
||||
# Libraty throws theese after connection is closed
|
||||
return
|
||||
@@ -167,7 +174,7 @@ class StdDaqClient(PSIDeviceBase):
|
||||
"""
|
||||
# pylint: disable=too-many-instance-attributes
|
||||
custom_prepare_cls = StdDaqMixin
|
||||
USER_ACCESS = ["set_daq_config", "get_daq_config", "safestop", "restart"]
|
||||
USER_ACCESS = ["set_daq_config", "get_daq_config", "safestop", "restart", "connect"]
|
||||
_wsclient = None
|
||||
|
||||
# Status attributes
|
||||
@@ -197,7 +204,6 @@ class StdDaqClient(PSIDeviceBase):
|
||||
self.ws_url.set(ws_url, force=True).wait()
|
||||
self.rest_url._metadata["write_access"] = False
|
||||
self.rest_url.set(rest_url, force=True).wait()
|
||||
self._mon = None
|
||||
|
||||
# Connect ro the DAQ and initialize values
|
||||
try:
|
||||
@@ -206,7 +212,10 @@ class StdDaqClient(PSIDeviceBase):
|
||||
logger.error(f"Failed to connect to the stdDAQ REST API\n{ex}")
|
||||
|
||||
def __del__(self) -> None:
|
||||
self._wsclient.close()
|
||||
try:
|
||||
self._wsclient.close()
|
||||
except TypeError:
|
||||
pass
|
||||
return super().__del__()
|
||||
|
||||
def connect(self):
|
||||
@@ -218,6 +227,7 @@ class StdDaqClient(PSIDeviceBase):
|
||||
num_retry = 0
|
||||
while num_retry < 5:
|
||||
try:
|
||||
logger.debug(f"[{self.name}] Connecting to {self.ws_url.get()}")
|
||||
self._wsclient = connect(self.ws_url.get())
|
||||
break
|
||||
except ConnectionRefusedError:
|
||||
@@ -226,6 +236,8 @@ class StdDaqClient(PSIDeviceBase):
|
||||
if num_retry == 5:
|
||||
raise ConnectionRefusedError(
|
||||
"The stdDAQ websocket interface refused connection 5 times.")
|
||||
logger.debug(f"[{self.name}] Connected to DAQ after {num_retry} tries")
|
||||
|
||||
|
||||
def message(self, message: dict, timeout=1, wait_reply=True):
|
||||
"""Send a message to the StdDAQ and receive a reply
|
||||
@@ -234,7 +246,6 @@ class StdDaqClient(PSIDeviceBase):
|
||||
there's no idle state polling.
|
||||
"""
|
||||
# Send message (reopen connection if needed)
|
||||
logger.warning(self._wsclient.__dict__)
|
||||
try:
|
||||
msg = json.dumps(message) if isinstance(message, dict) else str(message)
|
||||
self._wsclient.send(msg)
|
||||
|
||||
Reference in New Issue
Block a user