Fixed bug when trying to add a global function block instance variable to debug variable panel and not connected
authorLaurent Bessard
Thu, 13 Jun 2013 09:35:41 +0200
changeset 1254 ebc765355536
parent 1253 00b7d3c64c80
child 1255 ff59c6a8b793
Fixed bug when trying to add a global function block instance variable to debug variable panel and not connected
PLCControler.py
--- a/PLCControler.py	Wed Jun 12 23:51:33 2013 +0200
+++ b/PLCControler.py	Thu Jun 13 09:35:41 2013 +0200
@@ -649,14 +649,38 @@
                         return self.RecursiveGetPouInstanceTagName(project, vartype, parts[1:], debug)
         return None
     
+    def GetGlobalInstanceTagName(self, project, element, parts, debug = False):
+        for varlist in element.getglobalVars():
+            for variable in varlist.getvariable():
+                if variable.getname() == parts[0]:
+                    vartype_content = variable.gettype().getcontent()
+                    if vartype_content["name"] == "derived":                        
+                        if len(parts) == 1:
+                            return self.ComputePouName(
+                                        vartype_content["value"].getname())
+                        else:
+                            return self.RecursiveGetPouInstanceTagName(
+                                        project, 
+                                        vartype_content["value"].getname(),
+                                        parts[1:], debug)
+        return None
+    
     def GetPouInstanceTagName(self, instance_path, debug = False):
+        project = self.GetProject(debug)
         parts = instance_path.split(".")
         if len(parts) == 1:
             return self.ComputeConfigurationName(parts[0])
         elif len(parts) == 2:
+            for config in project.getconfigurations():
+                if config.getname() == parts[0]:
+                    result = self.GetGlobalInstanceTagName(project, 
+                                                           config, 
+                                                           parts[1:],
+                                                           debug)
+                    if result is not None:
+                        return result
             return self.ComputeConfigurationResourceName(parts[0], parts[1])
         else:
-            project = self.GetProject(debug)
             for config in project.getconfigurations():
                 if config.getname() == parts[0]:
                     for resource in config.getresource():
@@ -674,16 +698,26 @@
                                                     project,
                                                     pou_instance.gettypeName(),
                                                     parts[3:], debug)
+                            return self.GetGlobalInstanceTagName(project, 
+                                                                 resource, 
+                                                                 parts[2:], 
+                                                                 debug)
+                    return self.GetGlobalInstanceTagName(project, 
+                                                         config, 
+                                                         parts[1:],
+                                                         debug)
         return None
     
     def GetInstanceInfos(self, instance_path, debug = False):
         tagname = self.GetPouInstanceTagName(instance_path)
+        print instance_path, tagname
         if tagname is not None:
             infos = self.GetPouVariables(tagname, debug)
             infos["type"] = tagname
             return infos
         else:
             pou_path, var_name = instance_path.rsplit(".", 1)
+            print pou_path, tagname
             tagname = self.GetPouInstanceTagName(pou_path)
             if tagname is not None:
                 pou_infos = self.GetPouVariables(tagname, debug)