separate dealing with manager object into separate file; added PVInfo.to_dict()
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
from pcaspy.driver import manager, _ait_d as AIT_D
|
||||
|
||||
|
||||
D_AIT = {v:k for k, v in AIT_D.items()}
|
||||
|
||||
|
||||
def is_managed(name):
|
||||
managed_pvs = _get_managed_pvs()
|
||||
return (name in managed_pvs)
|
||||
|
||||
def get_managed_dtype(name):
|
||||
managed_pvs = _get_managed_pvs()
|
||||
pv = managed_pvs[name]
|
||||
dtype = pv.info.type
|
||||
return D_AIT[dtype]
|
||||
|
||||
def _get_managed_pvs():
|
||||
return manager.pvs["default"]
|
||||
|
||||
def delete_managed(prefix, name):
|
||||
del manager.pvs["default"][name]
|
||||
del manager.pvf[prefix + name]
|
||||
|
||||
|
||||
|
||||
+2
-3
@@ -2,10 +2,10 @@ from time import sleep
|
||||
from datetime import datetime
|
||||
from threading import Thread
|
||||
from pcaspy import SimpleServer, Driver
|
||||
from pcaspy.driver import manager
|
||||
|
||||
from context import Context
|
||||
from pvinfo import make_pvinfos, make_pvdb, make_values
|
||||
from managed import delete_managed
|
||||
|
||||
|
||||
INITIAL_PVDB = { #TODO make wait_time caput-able
|
||||
@@ -85,8 +85,7 @@ class MorIOC(Context):
|
||||
|
||||
def deletePV(self, name):
|
||||
name = name.upper()
|
||||
del manager.pvs["default"][name]
|
||||
del manager.pvf[self.prefix + name]
|
||||
delete_managed(self.prefix, name)
|
||||
|
||||
def setParams(self, **kwargs):
|
||||
for name, value in kwargs.items():
|
||||
|
||||
+9
-19
@@ -1,8 +1,6 @@
|
||||
from pcaspy.driver import manager, _ait_d as AIT_D
|
||||
from managed import is_managed, get_managed_dtype
|
||||
|
||||
|
||||
D_AIT = {v:k for k, v in AIT_D.items()}
|
||||
|
||||
#PV data type: enum, string, char, float or int
|
||||
DTYPES = {
|
||||
str: "string",
|
||||
@@ -27,6 +25,9 @@ class PVInfo:
|
||||
self.name = name.upper()
|
||||
self.dtype, self.value = infer_type(data, parse_string=parse_string)
|
||||
|
||||
def to_dict(self): #TODO count for arrays
|
||||
return {"type": self.dtype}
|
||||
|
||||
|
||||
|
||||
def infer_type(value, parse_string=True): #TODO arrays? strings?
|
||||
@@ -63,28 +64,17 @@ def make_pvdb(pvinfos):
|
||||
for pvi in pvinfos:
|
||||
name, dtype = pvi.name, pvi.dtype
|
||||
|
||||
if not pv_is_managed(name):
|
||||
if not is_managed(name):
|
||||
print("will create", name)
|
||||
pvdb[name] = {"type": dtype}
|
||||
pvdb[name] = pvi.to_dict()
|
||||
else:
|
||||
pv_type = get_managed_pv_type(name)
|
||||
if pv_type != dtype:
|
||||
print(f"type for {name} changed:", pv_type, "->", dtype) #TODO what should be done if this happens?
|
||||
managed_dtype = get_managed_dtype(name)
|
||||
if managed_dtype != dtype:
|
||||
print(f"type for {name} changed:", managed_dtype, "->", dtype) #TODO what should be done if this happens?
|
||||
# self.deletePV(name)
|
||||
# pvdb[name] = {"type": dtype}
|
||||
|
||||
return pvdb
|
||||
|
||||
|
||||
def pv_is_managed(name):
|
||||
managed_pvs = manager.pvs["default"]
|
||||
return name in managed_pvs
|
||||
|
||||
def get_managed_pv_type(name):
|
||||
managed_pvs = manager.pvs["default"]
|
||||
pv = managed_pvs[name]
|
||||
pv_type = pv.info.type
|
||||
return D_AIT[pv_type]
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -10,6 +10,10 @@ if __name__ == "__main__":
|
||||
with MorIOC("mtest") as mor:
|
||||
for i in range(1000):
|
||||
|
||||
mor.serve(
|
||||
rand2 = 1.23,
|
||||
)
|
||||
|
||||
mor.serve(
|
||||
rand1 = random(),
|
||||
rand2 = randint(100, 200),
|
||||
|
||||
Reference in New Issue
Block a user