plcopen/structures.py
changeset 151 aaa80b48bead
parent 125 394d9f168258
child 170 5068ba721506
equal deleted inserted replaced
150:f7832baaad84 151:aaa80b48bead
    32                      "W" : ["INT", "UINT", "WORD", "WSTRING"],
    32                      "W" : ["INT", "UINT", "WORD", "WSTRING"],
    33                      "D" : ["DINT", "UDINT", "REAL", "DWORD"],
    33                      "D" : ["DINT", "UDINT", "REAL", "DWORD"],
    34                      "L" : ["LINT", "ULINT", "LREAL", "LWORD"]} 
    34                      "L" : ["LINT", "ULINT", "LREAL", "LWORD"]} 
    35 
    35 
    36 def generate_block(generator, block, body, link, order=False):
    36 def generate_block(generator, block, body, link, order=False):
    37     body_type = body.getContent()["name"]
    37     body_type = body.getcontent()["name"]
    38     name = block.getInstanceName()
    38     name = block.getinstanceName()
    39     type = block.getTypeName()
    39     type = block.gettypeName()
    40     executionOrderId = block.getExecutionOrderId()
    40     executionOrderId = block.getexecutionOrderId()
    41     block_infos = GetBlockType(type)
    41     block_infos = GetBlockType(type)
    42     if block_infos["type"] == "function":
    42     if block_infos["type"] == "function":
    43         output_variable = block.outputVariables.getVariable()[0]
    43         output_variable = block.outputVariables.getvariable()[0]
    44         output_name = "%s%d_OUT"%(type, block.getLocalId())
    44         output_name = "%s%d_OUT"%(type, block.getlocalId())
    45         if not generator.ComputedBlocks.get(block, False) and not order:
    45         if not generator.ComputedBlocks.get(block, False) and not order:
    46             if generator.Interface[-1][0] != "VAR" or generator.Interface[-1][1] or generator.Interface[-1][2] or generator.Interface[-1][3]:
    46             if generator.Interface[-1][0] != "VAR" or generator.Interface[-1][1] or generator.Interface[-1][2] or generator.Interface[-1][3]:
    47                 generator.Interface.append(("VAR", False, False, False, []))
    47                 generator.Interface.append(("VAR", False, False, False, []))
    48             if output_variable.connectionPointOut in generator.ConnectionTypes:
    48             if output_variable.connectionPointOut in generator.ConnectionTypes:
    49                 generator.Interface[-1][4].append((generator.ConnectionTypes[output_variable.connectionPointOut], output_name, None, None))
    49                 generator.Interface[-1][4].append((generator.ConnectionTypes[output_variable.connectionPointOut], output_name, None, None))
    50             else:
    50             else:
    51                 generator.Interface[-1][4].append(("ANY", output_name, None, None))
    51                 generator.Interface[-1][4].append(("ANY", output_name, None, None))
    52             vars = []
    52             vars = []
    53             for variable in block.inputVariables.getVariable():
    53             for variable in block.inputVariables.getvariable():
    54                 connections = variable.connectionPointIn.getConnections()
    54                 connections = variable.connectionPointIn.getconnections()
    55                 if connections and len(connections) == 1:
    55                 if connections and len(connections) == 1:
    56                     if body_type == "FBD" or body_type == "SFC":
    56                     if body_type == "FBD" or body_type == "SFC":
    57                         value = generator.ComputeFBDExpression(body, connections[0], executionOrderId > 0)
    57                         value = generator.ComputeFBDExpression(body, connections[0], executionOrderId > 0)
    58                     elif body_type == "LD":
    58                     elif body_type == "LD":
    59                         paths = generator.GenerateLDPaths(variable.connectionPointIn.getConnections(), body)
    59                         paths = generator.GenerateLDPaths(variable.connectionPointIn.getConnections(), body)
    67             generator.ComputedBlocks[block] = True
    67             generator.ComputedBlocks[block] = True
    68         return generator.ExtractModifier(output_variable, output_name)
    68         return generator.ExtractModifier(output_variable, output_name)
    69     elif block_infos["type"] == "functionBlock":
    69     elif block_infos["type"] == "functionBlock":
    70         if not generator.ComputedBlocks.get(block, False) and not order:
    70         if not generator.ComputedBlocks.get(block, False) and not order:
    71             vars = []
    71             vars = []
    72             for variable in block.inputVariables.getVariable():
    72             for variable in block.inputVariables.getvariable():
    73                 connections = variable.connectionPointIn.getConnections()
    73                 connections = variable.connectionPointIn.getconnections()
    74                 if connections and len(connections) == 1:
    74                 if connections and len(connections) == 1:
    75                     parameter = variable.getFormalParameter()
    75                     parameter = variable.getformalParameter()
    76                     if body_type == "FBD" or body_type == "SFC":
    76                     if body_type == "FBD" or body_type == "SFC":
    77                         value = generator.ComputeFBDExpression(body, connections[0], executionOrderId > 0)
    77                         value = generator.ComputeFBDExpression(body, connections[0], executionOrderId > 0)
    78                         vars.append("%s := %s"%(parameter, generator.ExtractModifier(variable, value)))
    78                         vars.append("%s := %s"%(parameter, generator.ExtractModifier(variable, value)))
    79                     elif body_type == "LD":
    79                     elif body_type == "LD":
    80                         paths = generator.GenerateLDPaths(variable.connectionPointIn.getConnections(), body)
    80                         paths = generator.GenerateLDPaths(variable.connectionPointIn.getconnections(), body)
    81                         if len(paths) > 0:
    81                         if len(paths) > 0:
    82                             paths = tuple(paths)
    82                             paths = tuple(paths)
    83                         else:
    83                         else:
    84                             paths = paths[0] 
    84                             paths = paths[0] 
    85                         value = generator.ComputeLDExpression(paths, True)
    85                         value = generator.ComputeLDExpression(paths, True)
    86                     vars.append("%s := %s"%(parameter, generator.ExtractModifier(variable, value)))
    86                     vars.append("%s := %s"%(parameter, generator.ExtractModifier(variable, value)))
    87             generator.Program += "  %s(%s);\n"%(name, ", ".join(vars))
    87             generator.Program += "  %s(%s);\n"%(name, ", ".join(vars))
    88             generator.ComputedBlocks[block] = True
    88             generator.ComputedBlocks[block] = True
    89         if link:
    89         if link:
    90             connectionPoint = link.getPosition()[-1]
    90             connectionPoint = link.getposition()[-1]
    91         else:
    91         else:
    92             connectionPoint = None
    92             connectionPoint = None
    93         for variable in block.outputVariables.getVariable():
    93         for variable in block.outputVariables.getvariable():
    94             blockPointx, blockPointy = variable.connectionPointOut.getRelPosition()
    94             blockPointx, blockPointy = variable.connectionPointOut.getrelPositionXY()
    95             if not connectionPoint or block.getX() + blockPointx == connectionPoint.getX() and block.getY() + blockPointy == connectionPoint.getY():
    95             if not connectionPoint or block.getx() + blockPointx == connectionPoint.getx() and block.gety() + blockPointy == connectionPoint.gety():
    96                 return generator.ExtractModifier(variable, "%s.%s"%(name, variable.getFormalParameter()))
    96                 return generator.ExtractModifier(variable, "%s.%s"%(name, variable.getformalParameter()))
    97         raise ValueError, "No output variable found"
    97         raise ValueError, "No output variable found"
    98 
    98 
    99 def initialise_block(type, name):
    99 def initialise_block(type, name):
   100     return [(type, name, None, None)]
   100     return [(type, name, None, None)]
   101 
   101