diff --git a/bscache.py b/bscache.py index 4c30aef..1dec058 100644 --- a/bscache.py +++ b/bscache.py @@ -1,5 +1,5 @@ from time import sleep -from bsread import source +from bsread import source, dispatcher from bsvar import BSVar from prodthread import ProdThread @@ -38,6 +38,8 @@ class BSCache: def get_var(self, name, modulo=None, offset=None): if name is not "pid" and not name in self.channels: + if not is_available(name): + raise ValueError(f"channel {name} is not available") cfg = make_channel_config(name, modulo, offset) self.update_source(name, cfg) return BSVar(name, self) @@ -57,6 +59,16 @@ class BSCache: +def is_available(name): + available = get_available_channels() + return name in available + +def get_available_channels(): + channels = dispatcher.get_current_channels() + return set(ch["name"] for ch in channels) + + + def make_channel_config(name, modulo, offset): res = {} if modulo is not None: @@ -70,8 +82,6 @@ def make_channel_config(name, modulo, offset): - - def repack(channels, message): data = message.data.data pulse_id = message.data.pulse_id