PLCGenerator.py
changeset 104 a9b8916d906d
parent 93 c3c24b979a4d
child 108 9aa1fdfb7cb2
equal deleted inserted replaced
103:26c10e28ee3a 104:a9b8916d906d
   243                         self.ComputedConnectors[connector] = self.ComputeFBDExpression(body, connections[0])
   243                         self.ComputedConnectors[connector] = self.ComputeFBDExpression(body, connections[0])
   244         elif body_type == "LD":
   244         elif body_type == "LD":
   245             for instance in body.getContentInstances():
   245             for instance in body.getContentInstances():
   246                 if isinstance(instance, plcopen.coil):
   246                 if isinstance(instance, plcopen.coil):
   247                     paths = self.GenerateLDPaths(instance.connectionPointIn.getConnections(), body)
   247                     paths = self.GenerateLDPaths(instance.connectionPointIn.getConnections(), body)
       
   248                     if len(paths) > 0:
       
   249                         paths = tuple(paths)
       
   250                     else:
       
   251                         paths = paths[0] 
   248                     variable = self.ExtractModifier(instance, instance.getVariable())
   252                     variable = self.ExtractModifier(instance, instance.getVariable())
   249                     expression = self.ComputeLDExpression(paths, True)
   253                     expression = self.ComputeLDExpression(paths, True)
   250                     self.Program += "  %s := %s;\n"%(variable, expression)
   254                     self.Program += "  %s := %s;\n"%(variable, expression)
   251         elif body_type == "SFC":
   255         elif body_type == "SFC":
   252             for instance in body.getContentInstances():
   256             for instance in body.getContentInstances():
   273         localid = link.getRefLocalId()
   277         localid = link.getRefLocalId()
   274         instance = body.getContentInstance(localid)
   278         instance = body.getContentInstance(localid)
   275         if isinstance(instance, (plcopen.inVariable, plcopen.inOutVariable)):
   279         if isinstance(instance, (plcopen.inVariable, plcopen.inOutVariable)):
   276             return instance.getExpression()
   280             return instance.getExpression()
   277         elif isinstance(instance, plcopen.block):
   281         elif isinstance(instance, plcopen.block):
   278             type = instance.getTypeName()
   282             block_type = instance.getTypeName()
   279             block_infos = GetBlockType(type)
   283             block_infos = GetBlockType(block_type)
   280             return block_infos["generate"](self, instance, body, link)
   284             return block_infos["generate"](self, instance, body, link)
   281         elif isinstance(instance, plcopen.continuation):
   285         elif isinstance(instance, plcopen.continuation):
   282             name = instance.getName()
   286             name = instance.getName()
   283             computed_value = self.ComputedConnectors.get(name, None)
   287             computed_value = self.ComputedConnectors.get(name, None)
   284             if computed_value != None:
   288             if computed_value != None:
   298         for connection in connections:
   302         for connection in connections:
   299             localId = connection.getRefLocalId()
   303             localId = connection.getRefLocalId()
   300             next = body.getContentInstance(localId)
   304             next = body.getContentInstance(localId)
   301             if isinstance(next, plcopen.leftPowerRail):
   305             if isinstance(next, plcopen.leftPowerRail):
   302                 paths.append(None)
   306                 paths.append(None)
       
   307             elif isinstance(next, plcopen.block):
       
   308                 block_type = next.getTypeName()
       
   309                 block_infos = GetBlockType(block_type)
       
   310                 paths.append(block_infos["generate"](self, next, body, connection))
   303             else:
   311             else:
   304                 variable = self.ExtractModifier(next, next.getVariable())
   312                 variable = self.ExtractModifier(next, next.getVariable())
   305                 result = self.GenerateLDPaths(next.connectionPointIn.getConnections(), body)
   313                 result = self.GenerateLDPaths(next.connectionPointIn.getConnections(), body)
   306                 if len(result) > 1:
   314                 if len(result) > 1:
   307                     paths.append([variable, tuple(result)])
   315                     paths.append([variable, tuple(result)])