plcopen/structures.py
changeset 104 a9b8916d906d
parent 99 2b18a72dcaf0
child 108 9aa1fdfb7cb2
equal deleted inserted replaced
103:26c10e28ee3a 104:a9b8916d906d
    25 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    25 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    26 
    26 
    27 
    27 
    28 LANGUAGES = ["IL","ST","FBD","LD","SFC"]
    28 LANGUAGES = ["IL","ST","FBD","LD","SFC"]
    29 
    29 
       
    30 LOCATIONDATATYPES = {"X" : ["BOOL"],
       
    31                      "B" : ["SINT", "USINT", "BYTE", "STRING"],
       
    32                      "W" : ["INT", "UINT", "WORD", "WSTRING"],
       
    33                      "D" : ["DINT", "UDINT", "REAL", "DWORD"],
       
    34                      "L" : ["LINT", "ULINT", "LREAL", "LWORD"]} 
       
    35 
    30 def generate_block(generator, block, body, link):
    36 def generate_block(generator, block, body, link):
       
    37     body_type = body.getContent()["name"]
    31     name = block.getInstanceName()
    38     name = block.getInstanceName()
    32     type = block.getTypeName()
    39     type = block.getTypeName()
    33     block_infos = GetBlockType(type)
    40     block_infos = GetBlockType(type)
    34     if block_infos["type"] == "function" and link:
    41     if block_infos["type"] == "function" and link:
    35         generator.GeneratePouProgram(type)
    42         generator.GeneratePouProgram(type)
    36         vars = []
    43         vars = []
    37         for variable in block.inputVariables.getVariable():
    44         for variable in block.inputVariables.getVariable():
    38             connections = variable.connectionPointIn.getConnections()
    45             connections = variable.connectionPointIn.getConnections()
    39             if connections and len(connections) == 1:
    46             if connections and len(connections) == 1:
    40                 value = generator.ComputeFBDExpression(body, connections[0])
    47                 if body_type == "FBD":
       
    48                     value = generator.ComputeFBDExpression(body, connections[0])
       
    49                 elif body_type == "LD":
       
    50                     paths = generator.GenerateLDPaths(variable.connectionPointIn.getConnections(), body)
       
    51                     if len(paths) > 0:
       
    52                         paths = tuple(paths)
       
    53                     else:
       
    54                         paths = paths[0] 
       
    55                     value = generator.ComputeLDExpression(paths, True)
    41                 vars.append(generator.ExtractModifier(variable, value))
    56                 vars.append(generator.ExtractModifier(variable, value))
    42         variable = block.outputVariables.getVariable()[0]
    57         variable = block.outputVariables.getVariable()[0]
    43         return generator.ExtractModifier(variable, "%s(%s)"%(type, ", ".join(vars)))
    58         return generator.ExtractModifier(variable, "%s(%s)"%(type, ", ".join(vars)))
    44     elif block_infos["type"] == "functionBlock":
    59     elif block_infos["type"] == "functionBlock":
    45         if not generator.ComputedBlocks.get(name, False):
    60         if not generator.ComputedBlocks.get(name, False):
    46             vars = []
    61             vars = []
    47             for variable in block.inputVariables.getVariable():
    62             for variable in block.inputVariables.getVariable():
    48                 connections = variable.connectionPointIn.getConnections()
    63                 connections = variable.connectionPointIn.getConnections()
    49                 if connections and len(connections) == 1:
    64                 if connections and len(connections) == 1:
    50                     parameter = variable.getFormalParameter()
    65                     parameter = variable.getFormalParameter()
    51                     value = generator.ComputeFBDExpression(body, connections[0])
    66                     if body_type == "FBD":
       
    67                         value = generator.ComputeFBDExpression(body, connections[0])
       
    68                         vars.append("%s := %s"%(parameter, generator.ExtractModifier(variable, value)))
       
    69                     elif body_type == "LD":
       
    70                         paths = generator.GenerateLDPaths(variable.connectionPointIn.getConnections(), body)
       
    71                         if len(paths) > 0:
       
    72                             paths = tuple(paths)
       
    73                         else:
       
    74                             paths = paths[0] 
       
    75                         value = generator.ComputeLDExpression(paths, True)
    52                     vars.append("%s := %s"%(parameter, generator.ExtractModifier(variable, value)))
    76                     vars.append("%s := %s"%(parameter, generator.ExtractModifier(variable, value)))
    53             generator.Program += "  %s(%s);\n"%(name, ", ".join(vars))
    77             generator.Program += "  %s(%s);\n"%(name, ", ".join(vars))
    54             generator.ComputedBlocks[name] = True
    78             generator.ComputedBlocks[name] = True
    55         if link:
    79         if link:
    56             connectionPoint = link.getPosition()[-1]
    80             connectionPoint = link.getPosition()[-1]