# HG changeset patch # User lbessard # Date 1191600025 -7200 # Node ID a9b8916d906d423913b0d4b5b6fc8139af14fa8f # Parent 26c10e28ee3af763dc5be1992fc5d146a2281d41 Adding support for generation of blocks in LD diff -r 26c10e28ee3a -r a9b8916d906d PLCGenerator.py --- a/PLCGenerator.py Fri Oct 05 17:59:34 2007 +0200 +++ b/PLCGenerator.py Fri Oct 05 18:00:25 2007 +0200 @@ -245,6 +245,10 @@ for instance in body.getContentInstances(): if isinstance(instance, plcopen.coil): paths = self.GenerateLDPaths(instance.connectionPointIn.getConnections(), body) + if len(paths) > 0: + paths = tuple(paths) + else: + paths = paths[0] variable = self.ExtractModifier(instance, instance.getVariable()) expression = self.ComputeLDExpression(paths, True) self.Program += " %s := %s;\n"%(variable, expression) @@ -275,8 +279,8 @@ if isinstance(instance, (plcopen.inVariable, plcopen.inOutVariable)): return instance.getExpression() elif isinstance(instance, plcopen.block): - type = instance.getTypeName() - block_infos = GetBlockType(type) + block_type = instance.getTypeName() + block_infos = GetBlockType(block_type) return block_infos["generate"](self, instance, body, link) elif isinstance(instance, plcopen.continuation): name = instance.getName() @@ -300,6 +304,10 @@ next = body.getContentInstance(localId) if isinstance(next, plcopen.leftPowerRail): paths.append(None) + elif isinstance(next, plcopen.block): + block_type = next.getTypeName() + block_infos = GetBlockType(block_type) + paths.append(block_infos["generate"](self, next, body, connection)) else: variable = self.ExtractModifier(next, next.getVariable()) result = self.GenerateLDPaths(next.connectionPointIn.getConnections(), body) diff -r 26c10e28ee3a -r a9b8916d906d plcopen/structures.py --- 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