Commit 6ed99602 authored by Jose Tiago Macara Coutinho's avatar Jose Tiago Macara Coutinho
Browse files

wip 1

parent d60d63db
......@@ -315,11 +315,13 @@ TYPE_MAP = {
class Param(object):
def __init__(self, param_info):
def __init__(self, param_info, encode=None, decode=None):
self.info = param_info
dtype = TYPE_MAP[param_info['type']]
self.info['dtype'] = dtype
self.name = param_info['DDE']
self.encode = encode
self.decode = decode
def __getitem__(self, item):
return self.info[item]
......@@ -330,19 +332,17 @@ class Param(object):
result = obj.putget(cmd)
_check_error(result)
value = decode(result, dtype=dtype)
scale = self['scale']
if scale:
value /= scale
if self.decode:
value = self.decode(value)
obj.cache[self.name] = value
return value
def write(self, obj, value):
scale = self['scale']
dtype = self['dtype']
if scale is not None:
value *= scale
if dtype != DataType.FLOAT32:
value = int(value)
if self.encode:
value = self.encode(value)
elif dtype != DataType.FLOAT32:
value = int(value)
cmd = encode_write(obj.node, self['process'], self['parameter'], dtype,
value)
result = obj.putget(cmd)
......@@ -371,6 +371,9 @@ class Param(object):
return self.set(obj, value)
from .mapping import PARAM_DDE_MAP
class FlowBusNode(object):
def __init__(self, flowbus, node, auto_init=True):
......@@ -388,13 +391,11 @@ class FlowBusNode(object):
assert(self.node == pna)
def __str__(self):
return 'Node(pna={0.pna}, nna={0.nna}, type={0.DeviceType}, ' \
'model={0.ModelNum}, ID={0.identstrng}, SerialNb={0.SerialNum})' \
return 'Node(pna={0.pna}, nna={0.nna}, ID={0.identstrng})' \
.format(self)
def __repr__(self):
return 'FlowBusNode(pna={0.pna}, nna={0.nna}, type={0.DeviceType}, ' \
'model={0.ModelNum}, ID={0.identstrng}, SerialNb={0.SerialNum}) ' \
return 'FlowBusNode(pna={0.pna}, nna={0.nna}, ID={0.identstrng}) ' \
'object at 0x{1:x}'.format(self, id(self))
def putget(self, cmd):
......@@ -404,8 +405,8 @@ class FlowBusNode(object):
def flowbus(self):
return self.__flowbus()
identstrng = Param(PARAM_DDE_MAP['identstrng'], decode=lambda x: x[1:])
from .mapping import PARAM_DDE_MAP
for param_name, param_info in PARAM_DDE_MAP.items():
if hasattr(FlowBusNode, param_name):
......
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment