plcopen/plcopen.py
changeset 435 893d04aff708
parent 427 22d16c457d87
child 461 649a8465148d
--- 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)