From e7510fa315f306a32d308315d5620f8dda664548 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Fri, 13 Feb 2015 16:35:21 -0500 Subject: [PATCH] update ptable dset --- devsupApp/src/devsup/ptable.py | 87 +++++++++++++++++++++------------- documentation/ptable.rst | 2 +- testApp/test6.db | 8 ++-- 3 files changed, 60 insertions(+), 37 deletions(-) diff --git a/devsupApp/src/devsup/ptable.py b/devsupApp/src/devsup/ptable.py index 4ad3d30..4cc7127 100644 --- a/devsupApp/src/devsup/ptable.py +++ b/devsupApp/src/devsup/ptable.py @@ -209,7 +209,7 @@ class _ParamGroupInstance(object): return False return True -class _ParamSup(object): +class _ParamSupBase(object): def __init__(self, inst, rec, info): self.inst, self.info = inst, info # Determine which field to use to store the value @@ -224,35 +224,47 @@ class _ParamSup(object): def allowScan(self, rec): if self.inst.scan: return self.inst.scan.add(rec) - def process(self, rec, reason=None): - with self.inst.table.lock: - if reason is _INTERNAL: - # sync table to record - self.inst.table.log.debug('-> %s (%s)', rec.NAME, self.inst.value) - nval = self.inst.value - if nval is not None: - if self.vdata is None: - self.vfld.putval(nval) - else: - if len(nval)>len(self.vdata): - nval = nval[:len(self.vdata)] - self.vdata[:len(nval)] = nval - self.vfld.putarraylen(len(nval)) - if self.inst.alarm: - rec.setSevr(self.inst.alarm) - else: - # undefined value - rec.setSevr(INVALID_ALARM, UDF_ALARM) +class _ParamSupGet(_ParamSupBase): + def process(self, rec, reason=None): + """Read a value from the table into the record + """ + with self.inst.table.lock: + nval, alrm = self.inst.value, self.inst.alarm + self.inst.table.log.debug('%s -> %s (%s)', self.inst.name, rec.NAME, nval) + + if nval is not None: + if self.vdata is None: + self.vfld.putval(nval) else: - # sync record to table - self.inst.table.log.debug('<- %s (%s)', rec.NAME, rec.VAL) - if self.vdata is None: - nval = self.vfld.getval() - else: - # A copy is made which can be used without locking the record - nval = self.vdata[:self.vfld.getarraylen()].copy() - + if len(nval)>len(self.vdata): + nval = nval[:len(self.vdata)] + self.vdata[:len(nval)] = nval + self.vfld.putarraylen(len(nval)) + if alrm: + rec.setSevr(alrm) + else: + # undefined value + rec.setSevr(INVALID_ALARM, UDF_ALARM) + +class _ParamSupSet(_ParamSupGet): + def process(self, rec, reason=None): + """Write a value from the record into the table + """ + if reason is _INTERNAL: + # sync table to record + super(_ParamSupSet,self).process(rec,reason) + + else: + # sync record to table + self.inst.table.log.debug('%s <- %s (%s)', self.inst.name, rec.NAME, rec.VAL) + if self.vdata is None: + nval = self.vfld.getval() + else: + # A copy is made which can be used without locking the record + nval = self.vdata[:self.vfld.getarraylen()].copy() + + with self.inst.table.lock: oval, self.inst.value = self.inst.value, nval # Execute actions @@ -273,7 +285,8 @@ class TableBase(object): >>> """ log = LOG - ParamSupport = _ParamSup + ParamSupportGet = _ParamSupGet + ParamSupportSet = _ParamSupSet def __init__(self, **kws): self.name = kws.pop('name') if self.name in _tables: @@ -329,10 +342,20 @@ class TableBase(object): _tables[self.name] = self def build(rec, args): - parts = args.split(None,2) - table, param = parts[:2] - info = None if len(parts)<3 else parts[2] + """Device support pattern + + "@devsup.ptable set|get [optional]" + """ + parts = args.split(None,3) + table, param = parts[0], parts[2] + info = None if len(parts)<4 else parts[3] T = _tables[table] P = T._parameters[param] + if parts[1]=='set': + return T.ParamSupportSet(P, rec, info) + elif parts[1]=='get': + return T.ParamSupportGet(P, rec, info) + else: + raise ValueError("Not set or get") T.log.debug("Attaching ptable '%s, %s' to %s", T.name, P.name, rec.NAME) return T.ParamSupport(P, rec, info) diff --git a/documentation/ptable.rst b/documentation/ptable.rst index d5f1e70..a130f31 100644 --- a/documentation/ptable.rst +++ b/documentation/ptable.rst @@ -39,4 +39,4 @@ Device Support ^^^^^^^^^^^^^^ A general purpose device support is provided to access table parameters. -The input/output link format is "@devsup.ptable [optional]" +The input/output link format is "@devsup.ptable set|get [optional]" diff --git a/testApp/test6.db b/testApp/test6.db index 3517bb3..59fca88 100644 --- a/testApp/test6.db +++ b/testApp/test6.db @@ -1,22 +1,22 @@ record(ao, "$(P):A") { field(DTYP, "Python Device") - field(OUT , "@devsup.ptable $(TNAME) A") + field(OUT , "@devsup.ptable $(TNAME) set A") } record(ao, "$(P):B") { field(DTYP, "Python Device") - field(OUT , "@devsup.ptable $(TNAME) B") + field(OUT , "@devsup.ptable $(TNAME) set B") } record(ao, "$(P):C") { field(DTYP, "Python Device") - field(OUT , "@$(TNAME) C") + field(OUT , "@$(TNAME) set C") info("pySupportMod", "devsup.ptable") } record(ai, "$(P):S") { field(DTYP, "Python Device") - field(INP , "@devsup.ptable $(TNAME) S") + field(INP , "@devsup.ptable $(TNAME) get S") field(SCAN, "I/O Intr") field(PINI, "YES") }