Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cpp/control/src/LibXspressSimulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 0 additions & 6 deletions python/pyproject.toml

This file was deleted.

3 changes: 1 addition & 2 deletions python/src/xspress_detector/control/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down
47 changes: 32 additions & 15 deletions python/src/xspress_detector/control/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -573,20 +594,16 @@ 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
for i in range(len(value)):
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

Expand Down
4 changes: 2 additions & 2 deletions python/src/xspress_detector/control/xspress_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class XspressApi:
adapter_uri = "adapter"
process_uri = "process"
version_uri = "version"
command_uri = "command"
daq_uri = "daq"
app_uri = "app"

Expand Down Expand Up @@ -104,5 +105,4 @@ class XspressApi:
"patch": 0,
"short": "",
}
}

}
Loading