# HG changeset patch # User lbessard # Date 1221478623 -7200 # Node ID 351d134babd790812f27b158e8f2389c4ff39002 # Parent 34eff05909b039876edcd62e86218f910eedfa87 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support) Adding support for rising and falling edge in coil and fixing coil ST generation diff -r 34eff05909b0 -r 351d134babd7 plcopen/structures.py --- a/plcopen/structures.py Fri Sep 12 16:23:40 2008 +0200 +++ b/plcopen/structures.py Mon Sep 15 13:37:03 2008 +0200 @@ -44,24 +44,39 @@ executionOrderId = block.getexecutionOrderId() block_infos = generator.GetBlockType(type) if block_infos["type"] == "function": - output_variable = block.outputVariables.getvariable()[0] - output_name = "%s%d_OUT"%(type, block.getlocalId()) - output_info = (generator.TagName, "block", block.getlocalId(), "output", 0) + output_variables = block.outputVariables.getvariable() if not generator.ComputedBlocks.get(block, False) and not order: generator.ComputedBlocks[block] = True - if generator.Interface[-1][0] != "VAR" or generator.Interface[-1][1] or generator.Interface[-1][2] or generator.Interface[-1][3]: - generator.Interface.append(("VAR", False, False, False, [])) - if output_variable.connectionPointOut in generator.ConnectionTypes: - generator.Interface[-1][4].append((generator.ConnectionTypes[output_variable.connectionPointOut], output_name, None, None)) - else: - generator.Interface[-1][4].append(("ANY", output_name, None, None)) vars = [] for i, variable in enumerate(block.inputVariables.getvariable()): input_info = (generator.TagName, "block", block.getlocalId(), "input", i) connections = variable.connectionPointIn.getconnections() if connections is not None: value = generator.ComputeExpression(body, connections, executionOrderId > 0) - vars.append(generator.ExtractModifier(variable, value, input_info)) + if len(output_variables) > 1: + parameter = variable.getformalParameter() + vars.append([(parameter, input_info), + (" := ", ())] + generator.ExtractModifier(variable, value, input_info)) + else: + vars.append(generator.ExtractModifier(variable, value, input_info)) + for i, variable in enumerate(output_variables): + parameter = variable.getformalParameter() + if variable.getformalParameter() == "": + variable_name = "%s%d_OUT"%(type, block.getlocalId()) + else: + variable_name = "%s%d_%s"%(type, block.getlocalId(), parameter) + if generator.Interface[-1][0] != "VAR" or generator.Interface[-1][1] or generator.Interface[-1][2] or generator.Interface[-1][3]: + generator.Interface.append(("VAR", False, False, False, [])) + if variable.connectionPointOut in generator.ConnectionTypes: + generator.Interface[-1][4].append((generator.ConnectionTypes[variable.connectionPointOut], variable_name, None, None)) + else: + generator.Interface[-1][4].append(("ANY", variable_name, None, None)) + if len(output_variables) > 1 and parameter not in ["", "OUT"]: + vars.append([(parameter, (generator.TagName, "block", block.getlocalId(), "output", i)), + (" => %s"%variable_name, ())]) + else: + output_info = (generator.TagName, "block", block.getlocalId(), "output", i) + output_name = variable_name generator.Program += [(generator.CurrentIndent, ()), (output_name, output_info), (" := ", ()), @@ -69,7 +84,20 @@ ("(", ())] generator.Program += JoinList([(", ", ())], vars) generator.Program += [(");\n", ())] - return generator.ExtractModifier(output_variable, [(output_name, output_info)], output_info) + if link: + connectionPoint = link.getposition()[-1] + else: + connectionPoint = None + for i, variable in enumerate(output_variables): + blockPointx, blockPointy = variable.connectionPointOut.getrelPositionXY() + if not connectionPoint or block.getx() + blockPointx == connectionPoint.getx() and block.gety() + blockPointy == connectionPoint.gety(): + output_info = (generator.TagName, "block", block.getlocalId(), "output", i) + output_name = variable.getformalParameter() + if variable.getformalParameter() == "": + output_name = "%s%d_OUT"%(type, block.getlocalId()) + else: + output_name = "%s%d_%s"%(type, block.getlocalId(), variable.getformalParameter()) + return generator.ExtractModifier(variable, [(output_name, output_info)], output_info) elif block_infos["type"] == "functionBlock": if not generator.ComputedBlocks.get(block, False) and not order: generator.ComputedBlocks[block] = True @@ -93,10 +121,10 @@ connectionPoint = None for i, variable in enumerate(block.outputVariables.getvariable()): blockPointx, blockPointy = variable.connectionPointOut.getrelPositionXY() - output_info = (generator.TagName, "block", block.getlocalId(), "output", i) if not connectionPoint or block.getx() + blockPointx == connectionPoint.getx() and block.gety() + blockPointy == connectionPoint.gety(): + output_info = (generator.TagName, "block", block.getlocalId(), "output", i) return generator.ExtractModifier(variable, [("%s.%s"%(name, variable.getformalParameter()), output_info)], output_info) - raise ValueError, "No output variable found" + raise ValueError, "No output variable found" def initialise_block(type, name, block = None): return [(type, name, None, None)]