--- a/plcopen/structures.py Fri Oct 05 17:59:34 2007 +0200
+++ b/plcopen/structures.py Fri Oct 05 18:00:25 2007 +0200
@@ -27,7 +27,14 @@
LANGUAGES = ["IL","ST","FBD","LD","SFC"]
+LOCATIONDATATYPES = {"X" : ["BOOL"],
+ "B" : ["SINT", "USINT", "BYTE", "STRING"],
+ "W" : ["INT", "UINT", "WORD", "WSTRING"],
+ "D" : ["DINT", "UDINT", "REAL", "DWORD"],
+ "L" : ["LINT", "ULINT", "LREAL", "LWORD"]}
+
def generate_block(generator, block, body, link):
+ body_type = body.getContent()["name"]
name = block.getInstanceName()
type = block.getTypeName()
block_infos = GetBlockType(type)
@@ -37,7 +44,15 @@
for variable in block.inputVariables.getVariable():
connections = variable.connectionPointIn.getConnections()
if connections and len(connections) == 1:
- value = generator.ComputeFBDExpression(body, connections[0])
+ if body_type == "FBD":
+ value = generator.ComputeFBDExpression(body, connections[0])
+ elif body_type == "LD":
+ paths = generator.GenerateLDPaths(variable.connectionPointIn.getConnections(), body)
+ if len(paths) > 0:
+ paths = tuple(paths)
+ else:
+ paths = paths[0]
+ value = generator.ComputeLDExpression(paths, True)
vars.append(generator.ExtractModifier(variable, value))
variable = block.outputVariables.getVariable()[0]
return generator.ExtractModifier(variable, "%s(%s)"%(type, ", ".join(vars)))
@@ -48,7 +63,16 @@
connections = variable.connectionPointIn.getConnections()
if connections and len(connections) == 1:
parameter = variable.getFormalParameter()
- value = generator.ComputeFBDExpression(body, connections[0])
+ if body_type == "FBD":
+ value = generator.ComputeFBDExpression(body, connections[0])
+ vars.append("%s := %s"%(parameter, generator.ExtractModifier(variable, value)))
+ elif body_type == "LD":
+ paths = generator.GenerateLDPaths(variable.connectionPointIn.getConnections(), body)
+ if len(paths) > 0:
+ paths = tuple(paths)
+ else:
+ paths = paths[0]
+ value = generator.ComputeLDExpression(paths, True)
vars.append("%s := %s"%(parameter, generator.ExtractModifier(variable, value)))
generator.Program += " %s(%s);\n"%(name, ", ".join(vars))
generator.ComputedBlocks[name] = True