--- a/PLCControler.py Wed Jan 02 18:15:31 2008 +0100
+++ b/PLCControler.py Wed Jan 02 18:16:12 2008 +0100
@@ -328,17 +328,16 @@
for datatype in datatypes:
name = datatype.getName()
basetype_content = datatype.getBaseType().getContent()
- if basetype_content["value"] is not None:
- if basetype_content["name"] == "derived":
- basetype_name = basetype_content["value"].getName()
+ if basetype_content["name"] == "derived":
+ basetype_name = basetype_content["value"].getName()
+ if basetype_name in datatypenames and name not in self.DataTypeUsingTree[basetype_name]:
+ self.DataTypeUsingTree[basetype_name].append(name)
+ elif basetype_content["name"] in ["subrangeSigned", "subrangeUnsigned", "array"]:
+ base_type = basetype_content["value"].baseType.getContent()
+ if base_type["value"] is not None:
+ basetype_name = base_type["value"].getName()
if basetype_name in datatypenames and name not in self.DataTypeUsingTree[basetype_name]:
self.DataTypeUsingTree[basetype_name].append(name)
- elif basetype_content["name"] in ["subrangeSigned", "subrangeUnsigned", "array"]:
- base_type = basetype_content["value"].baseType.getContent()
- if base_type["value"] is not None:
- basetype_name = base_type["value"].getName()
- if basetype_name in datatypenames and name not in self.DataTypeUsingTree[basetype_name]:
- self.DataTypeUsingTree[basetype_name].append(name)
# Refresh the tree of user-defined pou cross-use
def RefreshPouUsingTree(self):
@@ -359,7 +358,7 @@
for type, varlist in pou.getVars():
for var in varlist.getVariable():
vartype_content = var.getType().getContent()
- if vartype_content["value"] is not None:
+ if vartype_content["name"] == "derived":
typename = vartype_content["value"].getName()
if typename in pounames and name not in self.PouUsingTree[typename]:
self.PouUsingTree[typename].append(name)
@@ -658,9 +657,14 @@
tempvar.setName(var["Name"])
var_type = plcopen.dataType()
if var["Type"] not in var_type.getChoices():
- derived_type = plcopen.derived()
- derived_type.setName(var["Type"])
- var_type.setContent("derived", derived_type)
+ if var["Type"] == "STRING":
+ var_type.setContent("string", plcopen.string())
+ elif var["Type"] == "WSTRING":
+ var_type.setContent("wstring", plcopen.wstring())
+ else:
+ derived_type = plcopen.derived()
+ derived_type.setName(var["Type"])
+ var_type.setContent("derived", derived_type)
else:
var_type.setContent(var["Type"], None)
tempvar.setType(var_type)
@@ -698,10 +702,12 @@
for var in varlist.getVariable():
tempvar = {"Name":var.getName(),"Class":"Global"}
vartype_content = var.getType().getContent()
- if vartype_content["value"] is None:
+ 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"]
- else:
- tempvar["Type"] = vartype_content["value"].getName()
tempvar["Edit"] = True
initial = var.getInitialValue()
if initial:
@@ -746,10 +752,12 @@
for var in varlist.getVariable():
tempvar = {"Name":var.getName(),"Class":"Global"}
vartype_content = var.getType().getContent()
- if vartype_content["value"] is None:
+ 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"]
- else:
- tempvar["Type"] = vartype_content["value"].getName()
tempvar["Edit"] = True
initial = var.getInitialValue()
if initial:
@@ -787,12 +795,15 @@
for var in varlist.getVariable():
tempvar = {"Name":var.getName(),"Class":type}
vartype_content = var.getType().getContent()
- if vartype_content["value"] is None:
- tempvar["Type"] = vartype_content["name"]
- tempvar["Edit"] = True
- else:
+ if vartype_content["name"] == "derived":
tempvar["Type"] = vartype_content["value"].getName()
tempvar["Edit"] = not pou.hasBlock(tempvar["Name"])
+ 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()
@@ -866,10 +877,12 @@
return_type = pou.interface.getReturnType()
if return_type:
returntype_content = return_type.getContent()
- if returntype_content["value"] is None:
+ if returntype_content["name"] == "derived":
+ return returntype_content["value"].getName()
+ elif returntype_content["name"] in ["string", "wstring"]:
+ return returntype_content["name"].upper()
+ else:
return returntype_content["name"]
- else:
- return returntype_content["value"].getName()
return None
# Update data types with user-defined data types added
@@ -882,6 +895,8 @@
basetype_content = datatype.getBaseType().getContent()
if basetype_content["value"] is None:
AddDataTypeHierarchy(name, basetype_content["name"])
+ elif basetype_content["name"] in ["string", "wstring"]:
+ AddDataTypeHierarchy(name, basetype_content["name"].upper())
elif basetype_content["name"] == "derived":
AddDataTypeHierarchy(name, basetype_content["value"].getName())
elif basetype_content["name"] in ["subrangeSigned", "subrangeUnsigned"]:
@@ -917,33 +932,42 @@
if type == "InOut":
for var in varlist.getVariable():
var_type = var.type.getContent()
- if var_type["value"] is None:
+ if var_type["name"] == "derived":
+ block_infos["inputs"].append((var.getName(),var_type["value"].getName(),"none"))
+ block_infos["outputs"].append((var.getName(),var_type["value"].getName(),"none"))
+ elif var_type["name"] in ["string", "wstring"]:
+ block_infos["inputs"].append((var.getName(),var_type["name"].upper(),"none"))
+ block_infos["outputs"].append((var.getName(),var_type["name"].upper(),"none"))
+ else:
block_infos["inputs"].append((var.getName(),var_type["name"],"none"))
block_infos["outputs"].append((var.getName(),var_type["name"],"none"))
- else:
- block_infos["inputs"].append((var.getName(),var_type["value"].getName(),"none"))
- block_infos["outputs"].append((var.getName(),var_type["value"].getName(),"none"))
elif type == "Input":
for var in varlist.getVariable():
var_type = var.type.getContent()
- if var_type["value"] is None:
+ if var_type["name"] == "derived":
+ block_infos["inputs"].append((var.getName(),var_type["value"].getName(),"none"))
+ elif var_type["name"] in ["string", "wstring"]:
+ block_infos["inputs"].append((var.getName(),var_type["name"].upper(),"none"))
+ else:
block_infos["inputs"].append((var.getName(),var_type["name"],"none"))
- else:
- block_infos["inputs"].append((var.getName(),var_type["value"].getName(),"none"))
elif type == "Output":
for var in varlist.getVariable():
var_type = var.type.getContent()
- if var_type["value"] is None:
- block_infos["outputs"].append((var.getName(),var_type["name"],"none"))
+ if var_type["name"] == "derived":
+ block_infos["outputs"].append((var.getName(),var_type["value"].getName(),"none"))
+ elif var_type["name"] in ["string", "wstring"]:
+ block_infos["outputs"].append((var.getName(),var_type["name"].upper(),"none"))
else:
- block_infos["outputs"].append((var.getName(),var_type["value"].getName(),"none"))
+ block_infos["outputs"].append((var.getName(),var_type["name"],"none"))
return_type = pou.interface.getReturnType()
if return_type:
var_type = return_type.getContent()
- if var_type["value"] is None:
+ if var_type["name"] == "derived":
+ block_infos["outputs"].append(("",var_type["value"].getName(),"none"))
+ elif var_type["name"] in ["string", "wstring"]:
+ block_infos["outputs"].append(("",var_type["name"].upper(),"none"))
+ else:
block_infos["outputs"].append(("",var_type["name"],"none"))
- else:
- block_infos["outputs"].append(("",var_type["value"].getName(),"none"))
if pou.getBodyType() in ["FBD","LD","SFC"]:
for instance in pou.getInstances():
if isinstance(instance, plcopen.comment):
@@ -1123,7 +1147,12 @@
datatype = self.Project.getDataType(words[1])
if infos["type"] == "Directly":
if infos["base_type"] in self.GetBaseTypes():
- datatype.baseType.setContent(infos["base_type"], None)
+ if infos["base_type"] == "STRING":
+ datatype.baseType.setContent("string", plcopen.string())
+ elif infos["base_type"] == "WSTRING":
+ datatype.baseType.setContent("wstring", plcopen.wstring())
+ else:
+ datatype.baseType.setContent(infos["base_type"], None)
else:
derived_datatype = plcopen.derived()
derived_datatype.setName(infos["base_type"])
@@ -1158,7 +1187,12 @@
dimension_range.setUpper(int(dimension))
array.appendDimension(dimension_range)
if infos["base_type"] in self.GetBaseTypes():
- array.baseType.setContent(infos["base_type"], None)
+ if infos["base_type"] == "STRING":
+ array.baseType.setContent("string", plcopen.string())
+ elif infos["base_type"] == "WSTRING":
+ array.baseType.setContent("wstring", plcopen.wstring())
+ else:
+ array.baseType.setContent(infos["base_type"], None)
else:
derived_datatype = plcopen.derived()
derived_datatype.setName(infos["base_type"])
@@ -1600,10 +1634,12 @@
for var in varlist.getVariable():
if var.getName() == varname:
vartype_content = var.getType().getContent()
- if vartype_content["value"] is None:
+ if vartype_content["name"] == "derived":
+ return vartype_content["value"].getName()
+ elif vartype_content["name"] in ["string", "wstring"]:
+ return vartype_content["name"].upper()
+ else:
return vartype_content["name"]
- else:
- return vartype_content["value"].getName()
return None
def SetConnectionWires(self, connection, connector):
--- a/PLCGenerator.py Wed Jan 02 18:15:31 2008 +0100
+++ b/PLCGenerator.py Wed Jan 02 18:16:12 2008 +0100
@@ -61,18 +61,18 @@
datatype = currentProject.getDataType(datatype_name)
datatype_def = " %s :"%datatype.getName()
basetype_content = datatype.baseType.getContent()
- if basetype_content["value"] is None:
- datatype_def += " %s"%basetype_content["name"]
+ if basetype_content["name"] in ["string", "wstring"]:
+ datatype_def += " %s"%basetype_content["name"].upper()
elif basetype_content["name"] == "derived":
basetype_name = basetype_content["value"].getName()
GenerateDataType(basetype_name)
datatype_def += " %s"%basetype_name
elif basetype_content["name"] in ["subrangeSigned", "subrangeUnsigned"]:
base_type = basetype_content["value"].baseType.getContent()
- if base_type["value"] is None:
+ if base_type["name"] == "derived":
+ basetype_name = base_type["value"].getName()
+ else:
basetype_name = base_type["name"]
- else:
- basetype_name = base_type["value"].getName()
GenerateDataType(basetype_name)
min_value = basetype_content["value"].range.getLower()
max_value = basetype_content["value"].range.getUpper()
@@ -84,15 +84,19 @@
datatype_def += " (%s)"%", ".join(values)
elif basetype_content["name"] == "array":
base_type = basetype_content["value"].baseType.getContent()
- if base_type["value"] is None:
+ if base_type["name"] == "derived":
+ basetype_name = base_type["value"].getName()
+ elif base_type["name"] in ["string", "wstring"]:
+ basetype_name = base_type["name"].upper()
+ else:
basetype_name = base_type["name"]
- else:
- basetype_name = base_type["value"].getName()
GenerateDataType(basetype_name)
dimensions = []
for dimension in basetype_content["value"].getDimension():
dimensions.append("0..%d"%(dimension.getUpper() - 1))
datatype_def += " ARRAY [%s] OF %s"%(",".join(dimensions), basetype_name)
+ else:
+ datatype_def += " %s"%basetype_content["name"]
if datatype.initialValue is not None:
datatype_def += " := %s"%str(datatype.initialValue.getValue())
currentProgram += "%s;\n"%datatype_def
@@ -123,10 +127,12 @@
config += "\n"
for var in varlist.getVariable():
vartype_content = var.getType().getContent()
- if vartype_content["value"] is None:
+ if vartype_content["name"] == "derived":
+ var_type = vartype_content["value"].getName()
+ elif vartype_content["name"] in ["string", "wstring"]:
+ var_type = vartype_content["name"].upper()
+ else:
var_type = vartype_content["name"]
- else:
- var_type = vartype_content["value"].getName()
config += " %s "%var.getName()
address = var.getAddress()
if address:
@@ -160,10 +166,12 @@
resrce += "\n"
for var in varlist.getVariable():
vartype_content = var.getType().getContent()
- if vartype_content["value"] is None:
+ if vartype_content["name"] == "derived":
+ var_type = vartype_content["value"].getName()
+ elif vartype_content["name"] in ["string", "wstring"]:
+ var_type = vartype_content["name"].upper()
+ else:
var_type = vartype_content["name"]
- else:
- var_type = vartype_content["value"].getName()
resrce += " %s "%var.getName()
address = var.getAddress()
if address:
@@ -306,17 +314,7 @@
located = False
for var in varlist["value"].getVariable():
vartype_content = var.getType().getContent()
- if vartype_content["value"] is None:
- initial = var.getInitialValue()
- if initial:
- initial_value = initial.getValue()
- else:
- initial_value = None
- address = var.getAddress()
- if address:
- located = True
- variables.append((vartype_content["name"], var.getName(), address, initial_value))
- else:
+ if vartype_content["name"] == "derived":
var_type = vartype_content["value"].getName()
GeneratePouProgram(var_type)
blocktype = GetBlockType(var_type)
@@ -333,6 +331,19 @@
if address:
located = True
variables.append((vartype_content["value"].getName(), var.getName(), address, initial_value))
+ else:
+ initial = var.getInitialValue()
+ if initial:
+ initial_value = initial.getValue()
+ else:
+ initial_value = None
+ address = var.getAddress()
+ if address:
+ located = True
+ if vartype_content["name"] in ["string", "wstring"]:
+ variables.append((vartype_content["name"].upper(), var.getName(), address, initial_value))
+ else:
+ variables.append((vartype_content["name"], var.getName(), address, initial_value))
if len(variables) > 0:
self.Interface.append((varTypeNames[varlist["name"]], varlist["value"].getRetain(),
varlist["value"].getConstant(), located, variables))
@@ -348,10 +359,12 @@
var_type = self.GetVariableType(expression)
if expression == pou.getName():
returntype_content = pou.interface.getReturnType().getContent()
- if returntype_content["value"] is None:
+ if returntype_content["name"] == "derived":
+ var_type = returntype_content["value"].getName()
+ elif returntype_content["name"] in ["string", "wstring"]:
+ var_type = returntype_content["name"].upper()
+ else:
var_type = returntype_content["name"]
- else:
- var_type = returntype_content["value"].getName()
elif var_type is None:
var_type = expression.split("#")[0]
if isinstance(instance, (plcopen.inVariable, plcopen.inOutVariable)):
--- a/plcopen/TC6_XML_V10_B.xsd Wed Jan 02 18:15:31 2008 +0100
+++ b/plcopen/TC6_XML_V10_B.xsd Wed Jan 02 18:16:12 2008 +0100
@@ -571,7 +571,7 @@
<xsd:element name="DATE"/>
<xsd:element name="DT"/>
<xsd:element name="TOD"/>
- <xsd:element name="STRING">
+ <xsd:element name="string">
<xsd:complexType>
<xsd:annotation>
<xsd:documentation>The single byte character string type</xsd:documentation>
@@ -579,7 +579,7 @@
<xsd:attribute name="length" type="xsd:unsignedLong" use="optional"/>
</xsd:complexType>
</xsd:element>
- <xsd:element name="WSTRING">
+ <xsd:element name="wstring">
<xsd:complexType>
<xsd:annotation>
<xsd:documentation>The wide character (WORD) string type</xsd:documentation>
--- a/plcopen/plcopen.py Wed Jan 02 18:15:31 2008 +0100
+++ b/plcopen/plcopen.py Wed Jan 02 18:16:12 2008 +0100
@@ -465,7 +465,7 @@
for var in variables:
if var.getName() == old_name:
vartype_content = var.getType().getContent()
- if vartype_content["value"] is not None and vartype_content["value"].getName() == old_type:
+ if vartype_content["name"] == "derived" and vartype_content["value"].getName() == old_type:
var.setName(new_name)
vartype_content["value"].setName(new_type)
return