Adding support for individually adding variable to POU interface
authorlaurent
Thu, 24 Sep 2009 18:16:04 +0200
changeset 435 893d04aff708
parent 434 8a0dfd22c408
child 436 f3bb091f803f
Adding support for individually adding variable to POU interface
PLCControler.py
plcopen/plcopen.py
--- a/PLCControler.py	Thu Sep 24 18:13:54 2009 +0200
+++ b/PLCControler.py	Thu Sep 24 18:16:04 2009 +0200
@@ -75,6 +75,13 @@
                    "InOut" :    (plcopen.interface_inOutVars,    ITEM_VAR_INOUT)
                   }
 
+LOCATIONS_ITEMS = [LOCATION_PLUGIN,
+                   LOCATION_MODULE,
+                   LOCATION_GROUP,
+                   LOCATION_VAR_INPUT,
+                   LOCATION_VAR_OUTPUT,
+                   LOCATION_VAR_MEMORY] = range(6)
+
 ScriptDirectory = os.path.split(os.path.realpath(__file__))[0]
 
 def GetUneditableNames():
@@ -1170,6 +1177,9 @@
         for i in xrange(len(self.PluginTypes)):
             self.PluginTypes.pop(0)
 
+    def GetVariableLocationTree(self):
+        return []
+
     # Function that returns the block definition associated to the block type given
     def GetBlockType(self, type, inputs = None, debug = False):
         for category in BlockTypes + self.PluginTypes:
@@ -1848,7 +1858,7 @@
                     connection.setconnectionParameter(idx, None)
                 idx += 1
     
-    def AddEditedElementPouVar(self, tagname, type, name):
+    def AddEditedElementPouVar(self, tagname, type, name, location="", description=""):
         if self.Project is not None:
             words = tagname.split("::")
             if words[0] in ['P', 'T', 'A']:
@@ -1856,7 +1866,7 @@
                 if pou is not None:
                     if pou.interface is None:
                         pou.interface = plcopen.pou_interface()
-                    pou.addpouVar(type, name)
+                    pou.addpouVar(type, name, location, description)
             
     def ChangeEditedElementPouVar(self, tagname, old_type, old_name, new_type, new_name):
         if self.Project is not None:
--- a/plcopen/plcopen.py	Thu Sep 24 18:13:54 2009 +0200
+++ b/plcopen/plcopen.py	Thu Sep 24 18:16:04 2009 +0200
@@ -924,7 +924,7 @@
             self.interface.appendcontent({"name" : VarTypes[vartype], "value" : varlist})
     setattr(cls, "setvars", setvars)
     
-    def addpouVar(self, type, name):
+    def addpouVar(self, type, name, location="", description=""):
         if self.interface is None:
             self.interface = PLCOpenClasses["pou_interface"]()
         content = self.interface.getcontent()
@@ -938,10 +938,25 @@
         var = PLCOpenClasses["varListPlain_variable"]()
         var.setname(name)
         var_type = PLCOpenClasses["dataType"]()
-        derived_type = PLCOpenClasses["derivedTypes_derived"]()
-        derived_type.setname(type)
-        var_type.setcontent({"name" : "derived", "value" : derived_type})
+        if type in [x for x,y in TypeHierarchy_list if not x.startswith("ANY")]:
+            if type == "STRING":
+                var_type.setcontent({"name" : "string", "value" : PLCOpenClasses["elementaryTypes_string"]()})
+            elif type == "WSTRING":
+                var_type.setcontent({"name" : "wstring", "value" : PLCOpenClasses["elementaryTypes_wstring"]()})
+            else:
+                var_type.setcontent({"name" : type, "value" : None})
+        else:
+            derived_type = PLCOpenClasses["derivedTypes_derived"]()
+            derived_type.setname(type)
+            var_type.setcontent({"name" : "derived", "value" : derived_type})
         var.settype(var_type)
+        if location != "":
+            var.setaddress(location)
+        if description != "":
+            ft = PLCOpenClasses["formattedText"]()
+            ft.settext(description)
+            var.setdocumentation(ft)
+        
         content[-1]["value"].appendvariable(var)
     setattr(cls, "addpouVar", addpouVar)