Skip to content
Snippets Groups Projects
Commit f07b6718 authored by Roberto Borghes's avatar Roberto Borghes
Browse files

Bug fixes in tangolistener.py

parent ef6fcd1f
No related branches found
No related tags found
No related merge requests found
......@@ -37,6 +37,9 @@ class TangoDeviceListener():
self.__prx = None
self.debug(traceback.format_exc())
def __check_proxy(self):
if self.__prx is None:
self.__prx = PyTango.DeviceProxy(self.__devname)
def debug(self, msg):
if self.__dbg:
......@@ -48,7 +51,8 @@ class TangoDeviceListener():
def Attributes(self):
return self.__attributes.keys()
def addAttribute(self, attrname):
def addAttribute(self, attrname_in):
attrname = attrname_in.lower()
self.debug("Adding attribute %s" % attrname)
if attrname not in self.__attributes.keys():
self.__attributes[attrname] = {}
......@@ -59,6 +63,7 @@ class TangoDeviceListener():
self.__attributes[attrname]["last_update"] = 0
self.__attributes[attrname]["last_update_info"] = 0
try:
self.__check_proxy()
self.__prx.subscribe_event(attrname,
PyTango.EventType.CHANGE_EVENT,
self.__EventReceived,
......@@ -72,12 +77,14 @@ class TangoDeviceListener():
except:
pass
def __remAttribute(self, attrname):
def __remAttribute(self, attrname_in):
attrname = attrname_in.lower()
self.debug("Removed attribute %s" % attrname)
if attrname in self.__attributes.keys():
del self.__attributes[attrname]
def readAttribute(self, attrname):
def readAttribute(self, attrname_in):
attrname = attrname_in.lower()
if attrname in self.__attributes.keys():
self.__attributes[attrname]["last_access"] = time.time()
attrcontent = self.__attributes[attrname]["value"]
......@@ -85,12 +92,14 @@ class TangoDeviceListener():
attrcontent.info = self.__attributes[attrname]["info"]
return attrcontent
def readAttributeInfo(self, attrname):
def readAttributeInfo(self, attrname_in):
attrname = attrname_in.lower()
self.debug("Updating Info for attribute %s" % attrname)
info = None
if attrname in self.__attributes.keys():
self.__attributes[attrname]["last_update_info"] = time.time()
try:
self.__check_proxy()
info = self.__prx.attribute_query(attrname)
self.__attributes[attrname]["info"] = info
except:
......@@ -100,21 +109,25 @@ class TangoDeviceListener():
def readCommandInfo(self, cmdname):
info = None
try:
self.__check_proxy()
info = self.__prx.command_query(cmdname)
except:
pass
return info
def sendCommand(self, cmdname, value = None):
self.__check_proxy()
if value is not None:
return self.__prx.command_inout(cmdname, value)
else:
return self.__prx.command_inout(cmdname)
def writeAttribute(self, attrname, value = None):
self.__check_proxy()
self.__prx.write_attribute(attrname, value)
def readDeviceFullInfo(self):
self.__check_proxy()
aInfo = self.__prx.get_attribute_config(self.__prx.get_attribute_list())
cInfo = self.__prx.get_command_config()
return {"Attributes":aInfo, "Commands":cInfo}
......@@ -142,23 +155,27 @@ class TangoDeviceListener():
self.__loop = False
self.__lock.release()
def forceReadAttr(self,attrname):
def forceReadAttr(self,attrname_in):
attrname = attrname_in.lower()
if attrname in self.__attributes.keys():
try:
self.__check_proxy()
self.__attributes[attrname]["value"] = self.__prx.read_attribute(attrname)
except:
self.__attributes[attrname]["value"] = None
self.debug(attrname)
def forceUpdateAttr(self,attrname):
def forceUpdateAttr(self,attrname_in):
attrname = attrname_in.lower()
if attrname in self.__attributes.keys():
self.__attributes[attrname]["last_update"] = 0
def __EventReceived(self,event):
""" Private Thread Function """
self.debug("EventReceived",event)
self.debug("EventReceived %s" % event)
if not event.err:
self.__attributes[event.attr_name] = event.attr_value
attrname = event.attr_name.split("/")[-1]
self.__attributes[attrname]["value"] = event.attr_value
def __sleep(self, period):
self.__break_sleep = False
......@@ -177,23 +194,26 @@ class TangoDeviceListener():
next_time = time.time() + self.__interval
while self.__loop:
for a in list(self.__attributes.keys()):
if self.__attributes[a]["polled"]:
if (time.time() - self.__attributes[a]["last_access"]) > ATTR_REMOVE_PERIOD:
self.__remAttribute(a)
break
elif (time.time() - self.__attributes[a]["last_access"]) > ATTR_RELAX_PERIOD:
attrperiod = self.__relaxed_interval
else:
attrperiod = self.__normal_interval
if (time.time() - self.__attributes[a]["last_update"]) < attrperiod:
# too early for reading this attribute
break
# Read and update the attribute value
self.forceReadAttr(a)
# Read and update the attribute info if necessary
if (time.time() - self.__attributes[a]["last_update_info"]) > self.__info_update_interval:
self.readAttributeInfo(a)
self.__attributes[a]["last_update"] = time.time()
try:
if self.__attributes[a]["polled"]:
if (time.time() - self.__attributes[a]["last_access"]) > ATTR_REMOVE_PERIOD:
self.__remAttribute(a)
break
elif (time.time() - self.__attributes[a]["last_access"]) > ATTR_RELAX_PERIOD:
attrperiod = self.__relaxed_interval
else:
attrperiod = self.__normal_interval
if (time.time() - self.__attributes[a]["last_update"]) < attrperiod:
# too early for reading this attribute
break
# Read and update the attribute value
self.forceReadAttr(a)
# Read and update the attribute info if necessary
if (time.time() - self.__attributes[a]["last_update_info"]) > self.__info_update_interval:
self.readAttributeInfo(a)
self.__attributes[a]["last_update"] = time.time()
except:
self.debug(traceback.format_exc())
#
nap = self.__interval
if self.__strict_timing:
......
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