PLCGenerator.py
changeset 194 1b3f8b4f8e04
parent 191 d77f9b783ce8
child 201 d5b778dab4b0
equal deleted inserted replaced
193:e18e354a8006 194:1b3f8b4f8e04
   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"
   121         interface = pou.getinterface()
   121         pou_program.GenerateInterface(pou)
   122         if interface is not None:
       
   123             pou_program.GenerateInterface(interface)
       
   124         pou_program.GenerateConnectionTypes(pou)
   122         pou_program.GenerateConnectionTypes(pou)
   125         pou_program.GenerateProgram(pou)
   123         pou_program.GenerateProgram(pou)
   126         currentProgram += pou_program.GenerateSTProgram()
   124         currentProgram += pou_program.GenerateSTProgram()
   127 
   125 
   128 def GenerateConfiguration(configuration):
   126 def GenerateConfiguration(configuration):
   309         for i, related in enumerate(self.RelatedConnections):
   307         for i, related in enumerate(self.RelatedConnections):
   310             if connection in related:
   308             if connection in related:
   311                 return self.RelatedConnections.pop(i)
   309                 return self.RelatedConnections.pop(i)
   312         return [connection]
   310         return [connection]
   313     
   311     
   314     def GenerateInterface(self, interface):
   312     def GenerateInterface(self, pou):
   315         if self.Type == "FUNCTION":
   313         interface = pou.getinterface()
   316             returntype_content = interface.getreturnType().getcontent()
   314         if interface is not None:
   317             if returntype_content["value"] is None:
   315             body = pou.getbody()
   318                 self.ReturnType = returntype_content["name"]
   316             body_content = body.getcontent()
   319             else:
   317             if self.Type == "FUNCTION":
   320                 self.ReturnType = returntype_content["value"].getname()
   318                 returntype_content = interface.getreturnType().getcontent()
   321         for varlist in interface.getcontent():
   319                 if returntype_content["value"] is None:
   322             variables = []
   320                     self.ReturnType = returntype_content["name"]
   323             located = []
   321                 else:
   324             for var in varlist["value"].getvariable():
   322                     self.ReturnType = returntype_content["value"].getname()
   325                 vartype_content = var.gettype().getcontent()
   323             for varlist in interface.getcontent():
   326                 if vartype_content["name"] == "derived":
   324                 variables = []
   327                     var_type = vartype_content["value"].getname()
   325                 located = []
   328                     GeneratePouProgram(var_type)
   326                 for var in varlist["value"].getvariable():
   329                     blocktype = GetBlockType(var_type)
   327                     vartype_content = var.gettype().getcontent()
   330                     if blocktype is not None:
   328                     if vartype_content["name"] == "derived":
   331                         for variable in blocktype["initialise"](var_type, var.getname()):
   329                         var_type = vartype_content["value"].getname()
   332                             if variable[2] is not None:
   330                         GeneratePouProgram(var_type)
   333                                 located.append(variable)
   331                         blocktype = GetBlockType(var_type)
       
   332                         if blocktype is not None:
       
   333                             if body_content["name"] in ["FBD", "LD", "SFC"]:
       
   334                                 block = pou.getinstanceByName(var.getname())
   334                             else:
   335                             else:
   335                                 variables.append(variable)
   336                                 block = None
       
   337                             for variable in blocktype["initialise"](var_type, var.getname(), block):
       
   338                                 if variable[2] is not None:
       
   339                                     located.append(variable)
       
   340                                 else:
       
   341                                     variables.append(variable)
       
   342                         else:
       
   343                             initial = var.getinitialValue()
       
   344                             if initial:
       
   345                                 initial_value = initial.getvalue()
       
   346                             else:
       
   347                                 initial_value = None
       
   348                             address = var.getaddress()
       
   349                             if address is not None:
       
   350                                 located.append((vartype_content["value"].getname(), var.getname(), address, initial_value))
       
   351                             else:
       
   352                                 variables.append((vartype_content["value"].getname(), var.getname(), None, initial_value))
   336                     else:
   353                     else:
   337                         initial = var.getinitialValue()
   354                         initial = var.getinitialValue()
   338                         if initial:
   355                         if initial:
   339                             initial_value = initial.getvalue()
   356                             initial_value = initial.getvalue()
   340                         else:
   357                         else:
   341                             initial_value = None
   358                             initial_value = None
   342                         address = var.getaddress()
   359                         address = var.getaddress()
   343                         if address is not None:
   360                         if vartype_content["name"] in ["string", "wstring"]:
   344                             located.append((vartype_content["value"].getname(), var.getname(), address, initial_value))
   361                             if address is not None:
       
   362                                 located.append((vartype_content["name"].upper(), var.getname(), address, initial_value))
       
   363                             else:
       
   364                                 variables.append((vartype_content["name"].upper(), var.getname(), None, initial_value))
       
   365                         elif address is not None:
       
   366                             located.append((vartype_content["name"], var.getname(), address, initial_value))
   345                         else:
   367                         else:
   346                             variables.append((vartype_content["value"].getname(), var.getname(), None, initial_value))
   368                             variables.append((vartype_content["name"], var.getname(), None, initial_value))
   347                 else:
   369                 if len(variables) > 0:
   348                     initial = var.getinitialValue()
   370                     self.Interface.append((varTypeNames[varlist["name"]], varlist["value"].getretain(), 
   349                     if initial:
   371                                 varlist["value"].getconstant(), False, variables))
   350                         initial_value = initial.getvalue()
   372                 if len(located) > 0:
   351                     else:
   373                     self.Interface.append((varTypeNames[varlist["name"]], varlist["value"].getretain(), 
   352                         initial_value = None
   374                                 varlist["value"].getconstant(), True, located))
   353                     address = var.getaddress()
       
   354                     if vartype_content["name"] in ["string", "wstring"]:
       
   355                         if address is not None:
       
   356                             located.append((vartype_content["name"].upper(), var.getname(), address, initial_value))
       
   357                         else:
       
   358                             variables.append((vartype_content["name"].upper(), var.getname(), None, initial_value))
       
   359                     elif address is not None:
       
   360                         located.append((vartype_content["name"], var.getname(), address, initial_value))
       
   361                     else:
       
   362                         variables.append((vartype_content["name"], var.getname(), None, initial_value))
       
   363             if len(variables) > 0:
       
   364                 self.Interface.append((varTypeNames[varlist["name"]], varlist["value"].getretain(), 
       
   365                             varlist["value"].getconstant(), False, variables))
       
   366             if len(located) > 0:
       
   367                 self.Interface.append((varTypeNames[varlist["name"]], varlist["value"].getretain(), 
       
   368                             varlist["value"].getconstant(), True, located))
       
   369         
   375         
   370     def GenerateConnectionTypes(self, pou):
   376     def GenerateConnectionTypes(self, pou):
   371         body = pou.getbody()
   377         body = pou.getbody()
   372         body_content = body.getcontent()
   378         body_content = body.getcontent()
   373         body_type = body_content["name"]
   379         body_type = body_content["name"]