Skip to content
Snippets Groups Projects
Commit 45eb1d2a authored by Martin Scarcia's avatar Martin Scarcia
Browse files

pyhton3 + new config changes

parent 34d2e59c
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,7 @@ import sys
import os
sys.path.insert(0, os.path.abspath('.'))
from UserDict import UserDict
from collections import UserDict
import PyTango
import numpy as np
import importlib
......@@ -217,6 +217,9 @@ class Dynamic(PyTango.Device_4Impl):
self.myattrs = CaseLessDict()
self.read_functions = CaseLessDict()
self.write_functions = CaseLessDict()
#link to the Tango DB
self.db = PyTango.Database()
aux = self.FiltersScript.split('/')
path = '/'.join(aux[:-1])
if path:
......@@ -247,11 +250,9 @@ class Dynamic(PyTango.Device_4Impl):
self.set_state(PyTango.DevState.OFF)
return
#link to the Tango DB
self.db = PyTango.Database()
#creation of dynamic attributes from cfg script
dynattrs = self.cfg_module.createDynAttrsDict()
#creation of dynamic attributes.
for attr in dynattrs:
attr_obj = dynattrs[attr]
......@@ -276,25 +277,16 @@ class Dynamic(PyTango.Device_4Impl):
PyTango.Except.throw_exception("Exist",
"Attribute "+attr_obj.name+ " already defined",
"NewAttribute")
tango_type = dataType2TangoType(attr_obj.type.upper())
permission = READ_ONLY
if attr_obj.flag == READ_ONLY:
permission = PyTango.AttrWriteType.READ
elif attr_obj.flag == READ_WRITE:
permission = PyTango.AttrWriteType.READ_WRITE
elif attr_obj.flag == WRITE_ONLY:
#FIXME: check if it is possible to have write only
permission = PyTango.AttrWriteType.READ_WRITE
# It's possible to define python methods for calculating the attribute value
self.read_functions[attr_obj.name] = attr_obj.read_function
self.write_functions[attr_obj.name] = attr_obj.write_function
if attr_obj.dimension == 1:
attr = PyTango.Attr(str(attr_obj.name), tango_type, permission)
attr = PyTango.Attr(str(attr_obj.name), attr_obj.datatype, attr_obj.permission)
if attr_obj.memorized == 1:
attr.set_memorized()
self.add_attribute(attr, self.read_Scalar,self.write_Scalar)
if tango_type == PyTango.ArgType.DevString:
if attr_obj.datatype == PyTango.ArgType.DevString:
self.myattrs[attr_obj.name] = ""
else:
self.myattrs[attr_obj.name] = 0
......@@ -304,37 +296,37 @@ class Dynamic(PyTango.Device_4Impl):
dev_attr_props = self.db.get_device_attribute_property(self.get_name(),[attr_obj.name])
attr_prop = dev_attr_props[attr_obj.name]
for pr in attr_prop.keys():
if (pr == '__value') and (tango_type == PyTango.ArgType.DevString):
if (pr == '__value') and (attr_obj.datatype == PyTango.ArgType.DevString):
self.myattrs[attr_obj.name] = attr_prop['__value'][0]
elif (pr == '__value') and (tango_type == PyTango.ArgType.DevFloat):
elif (pr == '__value') and (attr_obj.datatype == PyTango.ArgType.DevFloat):
self.myattrs[attr_obj.name] = float(attr_prop['__value'][0])
elif (pr == '__value') and (tango_type == PyTango.ArgType.DevDouble):
elif (pr == '__value') and (attr_obj.datatype == PyTango.ArgType.DevDouble):
self.myattrs[attr_obj.name] = float(attr_prop['__value'][0])
elif (pr == '__value') and (tango_type == PyTango.ArgType.DevBoolean):
elif (pr == '__value') and (attr_obj.datatype == PyTango.ArgType.DevBoolean):
self.myattrs[attr_obj.name] = bool(attr_prop['__value'][0] == "True")
elif (pr == '__value'):
self.myattrs[attr_obj.name] = int(attr_prop['__value'][0])
elif isinstance(attr_obj.dimension, tuple):
sizx = attr_obj.dimension[0]
sizy = attr_obj.dimension[1]
attr = PyTango.ImageAttr(str(attr_obj.name), tango_type, permission,sizx, sizy)
attr = PyTango.ImageAttr(str(attr_obj.name), attr_obj.datatype, attr_obj.permission,sizx, sizy)
self.add_attribute(attr, self.read_Image, self.write_Image)
if attr_obj.default:
self.myattrs[attr_obj.name] = eval(attr_obj.default)
elif tango_type == PyTango.ArgType.DevString:
elif attr_obj.datatype == PyTango.ArgType.DevString:
self.myattrs[attr_obj.name] = [[],[]]
else:
self.myattrs[attr_obj.name] = np.zeros((sizy,sizx),fromPyTango2NumpyType(tango_type))
self.myattrs[attr_obj.name] = np.zeros((sizy,sizx),fromPyTango2NumpyType(attr_obj.datatype))
else :
self.debug_stream("Creation of attribute %s, dimension = %s" % (attr_obj.name, str(attr_obj.dimension)))
attr = PyTango.SpectrumAttr(str(attr_obj.name), tango_type, permission,attr_obj.dimension)
attr = PyTango.SpectrumAttr(str(attr_obj.name), attr_obj.datatype, attr_obj.permission,attr_obj.dimension)
self.add_attribute(attr, self.read_Spectrum, self.write_Spectrum)
if attr_obj.default:
self.myattrs[attr_obj.name] = eval(attr_obj.default)
elif tango_type == PyTango.ArgType.DevString:
elif attr_obj.datatype == PyTango.ArgType.DevString:
self.myattrs[attr_obj.name] = []
else:
self.myattrs[attr_obj.name] = np.zeros(attr_obj.dimension, fromPyTango2NumpyType(tango_type))
self.myattrs[attr_obj.name] = np.zeros(attr_obj.dimension, fromPyTango2NumpyType(attr_obj.datatype))
self.set_state(PyTango.DevState.ON)
......@@ -438,14 +430,18 @@ class Dynamic(PyTango.Device_4Impl):
# argin: DevVarStringArray Name - of the new scalar attribute\nDOUBLE, SHORT, LONG for the type of the attribute\n
#------------------------------------------------------------------
def NewScalar(self, argin):
#print "In ", self.get_name(), "::NewScalar()"
#print "In ", self.get_name(), "::NewScalar()
(name,typ) = processInputStringArray(argin)
attr = PyTango.Attr(name, typ,
PyTango.AttrWriteType.READ_WRITE)
if self.myattrs.has_key(name):
if name in self.myattrs:
PyTango.Except.throw_exception("Exist","Attribute "+name+ " already defined","NewAttribute")
self.add_attribute(attr, self.read_Scalar, self.write_Scalar,None)
self.myattrs[name] = 0
# init missing entries in dictionaries
self.read_functions[name] = ""
self.write_functions[name] = ""
#------------------------------------------------------------------
......@@ -462,13 +458,14 @@ class Dynamic(PyTango.Device_4Impl):
PyTango.AttrWriteType.READ_WRITE,
siz
)
if self.myattrs.has_key(name):
if name in self.myattrs:
PyTango.Except.throw_exception("Exist","Attribute "+name+ " already defined","NewAttribute")
self.add_attribute(attr, self.read_Spectrum, self.write_Spectrum,None)
self.myattrs[name] = np.zeros(siz,fromPyTango2NumpyType(typ))
self.myattrs[name] = np.zeros(siz,fromPyTango2NumpyType(typ))
# init missing entries in dictionaries
self.read_functions[name] = ""
self.write_functions[name] = ""
#------------------------------------------------------------------
# NewImage command:
#
......@@ -482,11 +479,13 @@ class Dynamic(PyTango.Device_4Impl):
attr = PyTango.ImageAttr(name, typ,
PyTango.AttrWriteType.READ_WRITE,
sizx, sizy)
if self.myattrs.has_key(name):
if name in self.myattrs:
PyTango.Except.throw_exception("Exist","Attribute "+name+ " already defined","NewAttribute")
self.add_attribute(attr, self.read_Image, self.write_Image,None)
self.myattrs[name] = np.zeros((sizy,sizx),fromPyTango2NumpyType(typ))
#print self.myattrs[name].dtype
# init missing entries in dictionaries
self.read_functions[name] = ""
self.write_functions[name] = ""
#------------------------------------------------------------------
......
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