PLCGenerator.py
changeset 214 a88b377f75cb
parent 208 c70aefcadf66
child 215 dd3381f38a9e
equal deleted inserted replaced
213:4931959ea256 214:a88b377f75cb
   115         pou = currentProject.getpou(pou_name)
   115         pou = currentProject.getpou(pou_name)
   116         pou_type = pou.getpouType()
   116         pou_type = pou.getpouType()
   117         if pou_type in pouTypeNames:
   117         if pou_type in pouTypeNames:
   118             pou_program = PouProgram(pou.getname(), pouTypeNames[pou_type])
   118             pou_program = PouProgram(pou.getname(), pouTypeNames[pou_type])
   119         else:
   119         else:
   120             raise PLCGenException, "Undefined pou type"
   120             raise PLCGenException, "Undefined pou type \"%s\""%pou_type
   121         pou_program.GenerateInterface(pou)
   121         pou_program.GenerateInterface(pou)
   122         pou_program.GenerateConnectionTypes(pou)
   122         pou_program.GenerateConnectionTypes(pou)
   123         pou_program.GenerateProgram(pou)
   123         pou_program.GenerateProgram(pou)
   124         currentProgram += pou_program.GenerateSTProgram()
   124         currentProgram += pou_program.GenerateSTProgram()
   125 
   125 
   563                         connections = tmp_instance.connectionPointIn.getconnections()
   563                         connections = tmp_instance.connectionPointIn.getconnections()
   564                         if connections and len(connections) == 1:
   564                         if connections and len(connections) == 1:
   565                             expression = self.ComputeFBDExpression(body, connections[0], order)
   565                             expression = self.ComputeFBDExpression(body, connections[0], order)
   566                             self.ComputedConnectors[name] = expression
   566                             self.ComputedConnectors[name] = expression
   567                             return expression
   567                             return expression
   568             raise PLCGenException, "No connector found"
   568             raise PLCGenException, "No connector found corresponding to \"%s\" continuation in \"%s\" POU"%(name, self.Name)
   569 
   569 
   570     def GenerateLDPaths(self, connections, body):
   570     def GenerateLDPaths(self, connections, body):
   571         paths = []
   571         paths = []
   572         for connection in connections:
   572         for connection in connections:
   573             localId = connection.getrefLocalId()
   573             localId = connection.getrefLocalId()
   784             elif transitionValues["type"] == "connection":
   784             elif transitionValues["type"] == "connection":
   785                 body = pou.getbody()
   785                 body = pou.getbody()
   786                 connections = transition.getconnections()
   786                 connections = transition.getconnections()
   787                 network_type = self.GetNetworkType(connections, body)
   787                 network_type = self.GetNetworkType(connections, body)
   788                 if network_type == None:
   788                 if network_type == None:
   789                     raise Exception
   789                     raise PLCGenException, "Type of network connected to transition impossible to define in \"%s\" POU"%self.Name
   790                 if len(connections) > 1 or network_type == "LD":
   790                 if len(connections) > 1 or network_type == "LD":
   791                     paths = self.GenerateLDPaths(connections, body)
   791                     paths = self.GenerateLDPaths(connections, body)
   792                     expression = self.ComputeLDExpression(paths, True)
   792                     expression = self.ComputeLDExpression(paths, True)
   793                     transition_infos["content"] = "\n    := %s;\n"%expression
   793                     transition_infos["content"] = "\n    := %s;\n"%expression
   794                     self.SFCComputedBlocks += self.Program
   794                     self.SFCComputedBlocks += self.Program
   843             if len(transition_infos["from"]) > 1:
   843             if len(transition_infos["from"]) > 1:
   844                 self.Program += "(%s)"%", ".join(transition_infos["from"])
   844                 self.Program += "(%s)"%", ".join(transition_infos["from"])
   845             elif len(transition_infos["from"]) == 1:
   845             elif len(transition_infos["from"]) == 1:
   846                 self.Program += "%s"%transition_infos["from"][0]
   846                 self.Program += "%s"%transition_infos["from"][0]
   847             else:
   847             else:
   848                 raise PLCGenException, "Not connected transition"
   848                 raise PLCGenException, "Transition with content \"%s\" not connected to a previous step in \"%s\" POU"%(transition_infos["content"], self.Name)
   849             self.Program += " TO "
   849             self.Program += " TO "
   850             if len(transition_infos["to"]) > 1:
   850             if len(transition_infos["to"]) > 1:
   851                 self.Program += "(%s)"%", ".join(transition_infos["to"])
   851                 self.Program += "(%s)"%", ".join(transition_infos["to"])
   852             elif len(transition_infos["to"]) == 1:
   852             elif len(transition_infos["to"]) == 1:
   853                 self.Program += "%s"%transition_infos["to"][0]
   853                 self.Program += "%s"%transition_infos["to"][0]
   854             else:
   854             else:
   855                 raise PLCGenException, "Not connected transition"
   855                 raise PLCGenException, "Transition with content \"%s\" not connected to a next step in \"%s\" POU"%(transition_infos["content"], self.Name)
   856             self.Program += transition_infos["content"]
   856             self.Program += transition_infos["content"]
   857             self.Program += "  END_TRANSITION\n\n"
   857             self.Program += "  END_TRANSITION\n\n"
   858             for step_name in transition_infos["to"]:
   858             for step_name in transition_infos["to"]:
   859                 self.ComputeSFCStep(step_name)
   859                 self.ComputeSFCStep(step_name)
   860         
   860         
   900     def GenerateSTProgram(self):
   900     def GenerateSTProgram(self):
   901         if self.ReturnType:
   901         if self.ReturnType:
   902             program = "%s %s : %s\n"%(self.Type, self.Name, self.ReturnType)
   902             program = "%s %s : %s\n"%(self.Type, self.Name, self.ReturnType)
   903         else:
   903         else:
   904             program = "%s %s\n"%(self.Type, self.Name)
   904             program = "%s %s\n"%(self.Type, self.Name)
       
   905         if len(self.Interface) == 0:
       
   906             raise PLCGenException, "No variable defined in \"%s\" POU"%self.Name
       
   907         if self.Program == "":
       
   908             raise PLCGenException, "No body defined in \"%s\" POU"%self.Name
   905         for list_type, retain, constant, located, variables in self.Interface:
   909         for list_type, retain, constant, located, variables in self.Interface:
   906             program += "  %s"%list_type
   910             program += "  %s"%list_type
   907             if retain:
   911             if retain:
   908                 program += " RETAIN"
   912                 program += " RETAIN"
   909             if constant:
   913             if constant: