Skip to content
Snippets Groups Projects
Commit 957f25b1 authored by Paulus Kruger's avatar Paulus Kruger
Browse files

method call added to i2cdirect. User yaml config

parent 72228623
No related branches found
No related tags found
No related merge requests found
Pipeline #46405 passed
......@@ -22,8 +22,10 @@ class i2cdirect():
self.conf.linkdevices()
self.conf.loaddrivers()
self.conf.linkdrivers()
self.name=self.conf.conf['name']
self.runmethod(self.name+"_Init")
def GetVal(self,name,N=1):
def GetVal(self,name):
varid=self.conf.getvarid(name);
if varid is None:
logging.error("Variable "+name+" not found")
......@@ -34,6 +36,7 @@ class i2cdirect():
data=data[0].data
return byte2var(var1,data),var1
def SetVal(self,name,data):
varid=self.conf.getvarid(name);
if varid is None:
......@@ -45,7 +48,7 @@ class i2cdirect():
return drv.OPCUASetVariable(varid,var1,data2,[])
def SetRegister(self,regname,value):
methodid=self.conf.getmethodid("RECVTR_Init");
methodid=self.conf.getmethodid(self.name+"_Init");
var1=self.conf.getmethod(methodid)
drv=var1.get('drivercls');
v1=self.conf.getdevreg(regname)
......@@ -55,3 +58,42 @@ class i2cdirect():
elif drv2: drv2.Setdevreg(v1,value,mask)
else: logging.warn("Driver not specified for instruction"+key)
def runmethod(self,methodname):
logging.info("Run method:"+methodname)
methodid=self.conf.getmethodid("methodname");
var1=self.conf.getmethod(methodid)
drv=var1.get('drivercls');
for inst in var1['instructions']:
for key,value in inst.items():
if not(isinstance(value,list)): value=[value]
logging.info(str(("Run instruction",key,value)));
if (key=='WAIT'):
time.sleep(value[0]/1000.)
continue;
v1=self.conf.getvarid(key)
if not(v1 is None):
if value[0]=='Update':
self.GetVal(key)
else:
self.SetVal(key,value)
continue;
v1=self.conf.getmethodid(key)
if v1:
self.runmethod(key)
continue;
v1=self.conf.getdevreg(key)
if v1:
mask=[]
drv2=v1.get('drivercls')
if value[0]=='Update':
if drv: drv.Getdevreg(v1,mask)
elif drv2: drv2.Getdevreg(v1,mask)
else: logging.warn("Driver not specified for instruction"+key)
else:
if drv: drv.Setdevreg(v1,value,mask)
elif drv2: drv2.Setdevreg(v1,value,mask)
else: logging.warn("Driver not specified for instruction"+key)
continue;
logging.warn("Unknown instruction "+key)
return
\ No newline at end of file
......@@ -29,6 +29,9 @@ def str2int(x):
class yamlconfig():
def __init__(self,yamlfile='RCU'):
if yamlfile.split('.')[-1]=='yaml':
self.conf=yaml.load(open(yamlfile), Loader=yaml.FullLoader)
else:
pkg = importlib_resources.files("pypcc")
pkg_data_file = pkg / "config" / (yamlfile+'.yaml')
self.conf=yaml.load(pkg_data_file.open(), Loader=yaml.FullLoader)
......
from i2cdirect import i2cdirect
from pypcc.i2cdirect import i2cdirect
from time import sleep
import logging
logging.basicConfig(level="ERROR",format='%(asctime)s [%(levelname)-8s,%(filename)-20s:%(lineno)-3d] %(message)s')
#logging.basicConfig(level="DEBUG",format='%(asctime)s [%(levelname)-8s,%(filename)-20s:%(lineno)-3d] %(message)s')
d1=i2cdirect('RECVTR_LB_TEST')
d1=i2cdirect('RECVTR_LB_TEST.yaml')
def RCU_off(d1):
logging.warning("Switch RCU Power off");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment