fix(simulation): fix simulated devices

This commit is contained in:
2025-10-15 15:24:25 +02:00
committed by Christian Appel
parent 8a964083dc
commit 051d665490
2 changed files with 12 additions and 37 deletions

View File

@@ -388,31 +388,13 @@ class SimCameraWithPSIComponents(SimCamera):
} }
progress = messages.ProgressMessage(**progress) progress = messages.ProgressMessage(**progress)
self.progress.put(progress) self.progress.put(progress)
self._set_async_signal() self.async_signal.put(
np.sum(data, 1), async_update={"type": "add", "max_shape": [None]}
)
status = self.task_handler.submit_task(trigger_cam) status = self.task_handler.submit_task(trigger_cam)
return status return status
def _set_async_signal(self, update_all: bool = False):
"""Set the async signal values.
Args:
update_all (bool): If True, update all signals. If False, update only hinted and normal signals.
"""
# pylint: disable=protected-access
for sig in self.async_1d._signals.values():
if update_all is True:
sig.put(np.random.random())
continue
if sig.kind in [Kind.hinted, Kind.normal]:
sig.put(np.random.random())
for sig in self.async_2d._signals.values():
if update_all is True:
sig.put(np.random.random())
continue
if sig.kind in [Kind.hinted, Kind.normal]:
sig.put(np.random.random())
def on_unstage(self): def on_unstage(self):
"""Unstage device""" """Unstage device"""
self._triggers_received = 0 self._triggers_received = 0

View File

@@ -207,33 +207,25 @@ class SimWaveform(Device):
waveform_shape = self.waveform_shape.get() waveform_shape = self.waveform_shape.get()
if async_update_type == "add_slice": if async_update_type == "add_slice":
if index is not None: if index is not None:
metadata = { async_update = {
"async_update": { "type": "add_slice",
"type": "add_slice", "index": index,
"index": index, "max_shape": [None, waveform_shape],
"max_shape": [None, waveform_shape],
}
} }
else: else:
metadata = {"async_update": {"type": "add", "max_shape": [None, waveform_shape]}} async_update = {"type": "add", "max_shape": [None, waveform_shape]}
elif async_update_type == "add": elif async_update_type == "add":
metadata = {"async_update": {"type": "add", "max_shape": [None]}} async_update = {"type": "add", "max_shape": [None]}
else: else:
# Again, this should never happen -> check_value,
# but just in case we raise an exception
raise ValueError( raise ValueError(
f"Invalid async_update type: {async_update_type} for device {self.name}" f"Invalid async_update type: {async_update_type} for device {self.name}"
) )
# TODO remove once BEC e2e test async data is updated to use AsyncSignal 'data'
msg = messages.DeviceMessage( msg = messages.DeviceMessage(
signals={self.waveform.name: {"value": value, "timestamp": time.time()}}, signals={self.waveform.name: {"value": value, "timestamp": time.time()}},
metadata=metadata, metadata={"async_update": async_update},
) )
self.data.put(
{self.data.name: {"value": value, "timestamp": time.time()}}, metadata=metadata
)
# Send the message to BEC # Send the message to BEC
self.connector.xadd( self.connector.xadd(
MessageEndpoints.device_async_readback( MessageEndpoints.device_async_readback(
@@ -242,6 +234,7 @@ class SimWaveform(Device):
{"data": msg}, {"data": msg},
expire=self._stream_ttl, expire=self._stream_ttl,
) )
self.data.put(value, async_update=async_update)
def stage(self) -> list[object]: def stage(self) -> list[object]:
"""Stage the camera for upcoming scan """Stage the camera for upcoming scan