diff --git a/cpp/control/src/LibXspressSimulator.cpp b/cpp/control/src/LibXspressSimulator.cpp index 1be003b..22f841d 100644 --- a/cpp/control/src/LibXspressSimulator.cpp +++ b/cpp/control/src/LibXspressSimulator.cpp @@ -607,6 +607,7 @@ int LibXspressSimulator::get_num_frames_read(int32_t *frames) int LibXspressSimulator::get_num_scalars(uint32_t *num_scalars) { *num_scalars = XSP3_SW_NUM_SCALERS; + return XSP_STATUS_OK; } int LibXspressSimulator::histogram_circ_ack(int channel, diff --git a/python/pyproject.toml b/python/pyproject.toml deleted file mode 100644 index 3141568..0000000 --- a/python/pyproject.toml +++ /dev/null @@ -1,6 +0,0 @@ -[build-system] -# To get a reproducible wheel, wheel must be pinned to the same version as in -# dls-python3, and setuptools must produce the same dist-info. Cap setuptools -# to the last version that didn't add License-File to METADATA -requires = ["setuptools<57", "wheel==0.33.1", "versioneer-518"] -build-backend = "setuptools.build_meta" diff --git a/python/src/xspress_detector/control/adapter.py b/python/src/xspress_detector/control/adapter.py index e7a8718..7d357e2 100644 --- a/python/src/xspress_detector/control/adapter.py +++ b/python/src/xspress_detector/control/adapter.py @@ -85,9 +85,8 @@ async def get(self, path, request): try: response = await self.detector.get(path) if not isinstance(response, dict): - response = {"value": response} + response = {path.split("/")[-1]: response} - respose = "{}".format(response) status_code = 200 except LookupError as e: response = {'invalid path': str(e)} diff --git a/python/src/xspress_detector/control/detector.py b/python/src/xspress_detector/control/detector.py index 2d8576a..50f5dea 100644 --- a/python/src/xspress_detector/control/detector.py +++ b/python/src/xspress_detector/control/detector.py @@ -377,7 +377,25 @@ def __init__( ) - self.param["module"] = self._name + self.param["module"] = {"value": self._name} + + self.param["command"] = {"allowed": ["reconfigure","start_acquisition","stop_acquisition", "trigger"], + "execute": ("", lambda name: self.run_command(name)) + } + + + async def run_command(self, name): + match name: + case "reconfigure": + await self.reconfigure(1) + case "start_acquisition": + await self.acquire(1) + case "stop_acquisition": + await self.acquire(0) + case "trigger": + await self.trigger() + case _: + logging.error(f"Unsupported command {name}") async def _get_value(self,path): return self._cache.get(path,None) @@ -517,7 +535,7 @@ async def reconfigure(self, *unused): resp = await self._async_client.send_recv(self.configuration.get()) # resp = await self._put(MessageType.CONFIG, XspressDetectorStr.CONFIG_CONFIG_PATH, self.settings_paths[mode]) - resp = await self._put(MessageType.CMD, "config/disconnect", 1) # Here disconnect is inside config + resp = await self._put(MessageType.CMD, "command/disconnect", 1) # Here disconnect is inside config chans = self.mca_channels if mode == XSPRESS_MODE_MCA else self.mca_channels + 1 await self._put( MessageType.CONFIG, "config/max_channels", chans @@ -531,17 +549,20 @@ async def reconfigure(self, *unused): resp = await self._async_client.send_recv(self.configuration.get_daq()) return resp - async def connect(self, *unused): - msg = _build_message(MessageType.CMD, {XspressDetectorStr.CMD_CONNECT: 1}) + async def connect(self, value: bool = True, *unused): + msg = _build_message(MessageType.CMD, {XspressDetectorStr.CMD_CONNECT: value}) return await self._async_client.send_recv(msg, timeout=20) - async def acquire(self, value, *unused): + async def acquire(self, value): if value: - reply = await self._put(MessageType.CMD, XspressDetectorStr.CMD_START, 1) + reply = await self._put(MessageType.CMD, "command/start", 1) self.acquisition_complete = False return reply else: - return await self._put(MessageType.CMD, XspressDetectorStr.CMD_STOP, 1) + return await self._put(MessageType.CMD, "command/stop", 1) + + async def trigger(self): + return await self._put(MessageType.CMD, "command/trigger", 1) async def set_mode(self, value): if value == 0: @@ -562,7 +583,7 @@ async def do_updates(self, value: int): def _set(self, attr_name, value): setattr(self, attr_name, value) - async def _put(self, message_type: MessageType, config_str: str, value: any): + async def _put(self, message_type: MessageType, path: str, value: any): if not self._param_tree_waited: self.parameter_tree = await AsyncParameterTree(self.param) self._param_tree_waited = True @@ -573,11 +594,7 @@ async def _put(self, message_type: MessageType, config_str: str, value: any): "Control server is not connected! Check if it is running and tcp endpoint is configured correctly" ) - field, item = config_str.split("/") - - # For when commands are available - if field == "command": - return self.COMMANDS[item](self,value) + _, item = path.split("/") if isinstance(value,list): index = 0 @@ -585,8 +602,8 @@ async def _put(self, message_type: MessageType, config_str: str, value: any): if value[i] != -1: index = i break - self._cache[config_str][index] = value[index] - msg = _build_message(message_type, {item: self._cache[config_str]}) + self._cache[path][index] = value[index] + msg = _build_message(message_type, {item: self._cache[path]}) resp = await self._async_client.send_recv(msg) return resp diff --git a/python/src/xspress_detector/control/xspress_api.py b/python/src/xspress_detector/control/xspress_api.py index 85a4d81..e95931a 100644 --- a/python/src/xspress_detector/control/xspress_api.py +++ b/python/src/xspress_detector/control/xspress_api.py @@ -5,6 +5,7 @@ class XspressApi: adapter_uri = "adapter" process_uri = "process" version_uri = "version" + command_uri = "command" daq_uri = "daq" app_uri = "app" @@ -104,5 +105,4 @@ class XspressApi: "patch": 0, "short": "", } - } - + } \ No newline at end of file