added availability check to BSCache.get_var()

This commit is contained in:
2021-09-08 13:52:42 +02:00
parent f42605e619
commit ab24e53b44

View File

@ -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