diff options
Diffstat (limited to 'core/acquisition.py')
| -rw-r--r-- | core/acquisition.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/core/acquisition.py b/core/acquisition.py index 79bdb79..f54f265 100644 --- a/core/acquisition.py +++ b/core/acquisition.py @@ -112,6 +112,24 @@ class AcquisitionEngine(QObject): for ch in dev.info.channels: self._last_units[(dev.info.device_id, ch.channel_id)] = ch.unit + def on_device_reconfigured(self, device_id: str): + """Reconcile buffers with a device's current channel list — reconfigure() + can add/remove channels (e.g. Signals count changed), and buffers keyed + by the old channel list would silently drop data for anything new.""" + dev = next((d for d in self._devices if d.info.device_id == device_id), None) + if dev is None: + return + bufs = self._buffers.setdefault(device_id, {}) + valid_ids = {ch.channel_id for ch in dev.info.channels} + for stale_id in [cid for cid in bufs if cid not in valid_ids]: + bufs.pop(stale_id, None) + for ch in dev.info.channels: + if ch.channel_id not in bufs: + bufs[ch.channel_id] = ChannelBuffer() + self._last_units[(device_id, ch.channel_id)] = ch.unit + for key in [k for k in self._last_units if k[0] == device_id and k[1] not in valid_ids]: + self._last_units.pop(key, None) + def remove_device(self, device_id: str): self._devices = [d for d in self._devices if d.info.device_id != device_id] self._buffers.pop(device_id, None) |
