added availability check to BSCache.get_var()
This commit is contained in:
16
bscache.py
16
bscache.py
@ -1,5 +1,5 @@
|
|||||||
from time import sleep
|
from time import sleep
|
||||||
from bsread import source
|
from bsread import source, dispatcher
|
||||||
from bsvar import BSVar
|
from bsvar import BSVar
|
||||||
from prodthread import ProdThread
|
from prodthread import ProdThread
|
||||||
|
|
||||||
@ -38,6 +38,8 @@ class BSCache:
|
|||||||
|
|
||||||
def get_var(self, name, modulo=None, offset=None):
|
def get_var(self, name, modulo=None, offset=None):
|
||||||
if name is not "pid" and not name in self.channels:
|
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)
|
cfg = make_channel_config(name, modulo, offset)
|
||||||
self.update_source(name, cfg)
|
self.update_source(name, cfg)
|
||||||
return BSVar(name, self)
|
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):
|
def make_channel_config(name, modulo, offset):
|
||||||
res = {}
|
res = {}
|
||||||
if modulo is not None:
|
if modulo is not None:
|
||||||
@ -70,8 +82,6 @@ def make_channel_config(name, modulo, offset):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def repack(channels, message):
|
def repack(channels, message):
|
||||||
data = message.data.data
|
data = message.data.data
|
||||||
pulse_id = message.data.pulse_id
|
pulse_id = message.data.pulse_id
|
||||||
|
Reference in New Issue
Block a user