--- a/PLCControler.py Mon Sep 14 10:57:12 2009 -0600
+++ b/PLCControler.py Tue Sep 15 14:06:59 2009 -0600
@@ -847,6 +847,7 @@
# Create variable and change its properties
tempvar = plcopen.varListPlain_variable()
tempvar.setname(var["Name"])
+
var_type = plcopen.dataType()
if var["Type"] in self.GetBaseTypes():
if var["Type"] == "STRING":
@@ -860,6 +861,7 @@
derived_type.setname(var["Type"])
var_type.setcontent({"name" : "derived", "value" : derived_type})
tempvar.settype(var_type)
+
if var["Initial Value"] != "":
value = plcopen.value()
value.setvalue(var["Initial Value"])
@@ -868,9 +870,62 @@
tempvar.setaddress(var["Location"])
else:
tempvar.setaddress(None)
+ if var['Documentation'] != "":
+ ft = plcopen.formattedText()
+ ft.settext(var['Documentation'])
+ tempvar.setdocumentation(ft)
+
# Add variable to varList
current_varlist.appendvariable(tempvar)
return varlist_list
+
+ def GetVariableDictionary(self, varlist, var):
+ '''
+ convert a PLC variable to the dictionary representation
+ returned by Get*Vars)
+ '''
+
+ tempvar = {"Name" : var.getname()}
+
+ vartype_content = var.gettype().getcontent()
+ if vartype_content["name"] == "derived":
+ tempvar["Type"] = vartype_content["value"].getname()
+ elif vartype_content["name"] in ["string", "wstring"]:
+ tempvar["Type"] = vartype_content["name"].upper()
+ else:
+ tempvar["Type"] = vartype_content["name"]
+
+ tempvar["Edit"] = True
+
+ initial = var.getinitialValue()
+ if initial:
+ tempvar["Initial Value"] = initial.getvalue()
+ else:
+ tempvar["Initial Value"] = ""
+
+ address = var.getaddress()
+ if address:
+ tempvar["Location"] = address
+ else:
+ tempvar["Location"] = ""
+
+ if varlist.getretain():
+ tempvar["Retain"] = "Yes"
+ else:
+ tempvar["Retain"] = "No"
+
+ if varlist.getconstant():
+ tempvar["Constant"] = "Yes"
+ else:
+ tempvar["Constant"] = "No"
+
+ doc = var.getdocumentation()
+ if doc:
+ tempvar["Documentation"] = doc.gettext()
+ else:
+ tempvar["Documentation"] = ""
+
+ return tempvar
# Replace the configuration globalvars by those given
def SetConfigurationGlobalVars(self, name, vars):
@@ -894,33 +949,8 @@
# Extract variables from every varLists
for varlist in configuration.getglobalVars():
for var in varlist.getvariable():
- tempvar = {"Name" : var.getname(), "Class" : "Global"}
- vartype_content = var.gettype().getcontent()
- if vartype_content["name"] == "derived":
- tempvar["Type"] = vartype_content["value"].getname()
- elif vartype_content["name"] in ["string", "wstring"]:
- tempvar["Type"] = vartype_content["name"].upper()
- else:
- tempvar["Type"] = vartype_content["name"]
- tempvar["Edit"] = True
- initial = var.getinitialValue()
- if initial:
- tempvar["Initial Value"] = initial.getvalue()
- else:
- tempvar["Initial Value"] = ""
- address = var.getaddress()
- if address:
- tempvar["Location"] = address
- else:
- tempvar["Location"] = ""
- if varlist.getretain():
- tempvar["Retain"] = "Yes"
- else:
- tempvar["Retain"] = "No"
- if varlist.getconstant():
- tempvar["Constant"] = "Yes"
- else:
- tempvar["Constant"] = "No"
+ tempvar = self.GetVariableDictionary(varlist, var)
+ tempvar["Class"] = "Global"
vars.append(tempvar)
return vars
@@ -946,33 +976,8 @@
# Extract variables from every varLists
for varlist in resource.getglobalVars():
for var in varlist.getvariable():
- tempvar = {"Name" : var.getname(), "Class" : "Global"}
- vartype_content = var.gettype().getcontent()
- if vartype_content["name"] == "derived":
- tempvar["Type"] = vartype_content["value"].getname()
- elif vartype_content["name"] in ["string", "wstring"]:
- tempvar["Type"] = vartype_content["name"].upper()
- else:
- tempvar["Type"] = vartype_content["name"]
- tempvar["Edit"] = True
- initial = var.getinitialValue()
- if initial:
- tempvar["Initial Value"] = initial.getvalue()
- else:
- tempvar["Initial Value"] = ""
- address = var.getaddress()
- if address:
- tempvar["Location"] = address
- else:
- tempvar["Location"] = ""
- if varlist.getretain():
- tempvar["Retain"] = "Yes"
- else:
- tempvar["Retain"] = "No"
- if varlist.getconstant():
- tempvar["Constant"] = "Yes"
- else:
- tempvar["Constant"] = "No"
+ tempvar = self.GetVariableDictionary(varlist, var)
+ tempvar["Class"] = "Global"
vars.append(tempvar)
return vars
@@ -1011,7 +1016,7 @@
tree.append((element.getname(), element_type["name"], ([], [])))
return tree, []
return [], []
-
+
# Return the interface for the given pou
def GetPouInterfaceVars(self, pou, debug = False):
vars = []
@@ -1020,36 +1025,16 @@
# Extract variables from every varLists
for type, varlist in pou.getvars():
for var in varlist.getvariable():
- tempvar = {"Name" : var.getname(), "Class" : type, "Tree" : ([], [])}
+ tempvar = self.GetVariableDictionary(varlist, var)
+
+ tempvar["Class"] = type
+ tempvar["Tree"] = ([], [])
+
vartype_content = var.gettype().getcontent()
if vartype_content["name"] == "derived":
- tempvar["Type"] = vartype_content["value"].getname()
tempvar["Edit"] = not pou.hasblock(tempvar["Name"])
tempvar["Tree"] = self.GenerateVarTree(tempvar["Type"], debug)
- else:
- if vartype_content["name"] in ["string", "wstring"]:
- tempvar["Type"] = vartype_content["name"].upper()
- else:
- tempvar["Type"] = vartype_content["name"]
- tempvar["Edit"] = True
- initial = var.getinitialValue()
- if initial:
- tempvar["Initial Value"] = initial.getvalue()
- else:
- tempvar["Initial Value"] = ""
- address = var.getaddress()
- if address:
- tempvar["Location"] = address
- else:
- tempvar["Location"] = ""
- if varlist.getretain():
- tempvar["Retain"] = "Yes"
- else:
- tempvar["Retain"] = "No"
- if varlist.getconstant():
- tempvar["Constant"] = "Yes"
- else:
- tempvar["Constant"] = "No"
+
vars.append(tempvar)
return vars