PLCGenerator.py
changeset 171 e3d47b4bbd5d
parent 168 fb500cc79164
child 189 43cd3ef83a1f
equal deleted inserted replaced
170:5068ba721506 171:e3d47b4bbd5d
    35 currentProject = None
    35 currentProject = None
    36 currentProgram = ""
    36 currentProgram = ""
    37 datatypeComputed = {}
    37 datatypeComputed = {}
    38 pouComputed = {}
    38 pouComputed = {}
    39 
    39 
       
    40 class PLCGenException(Exception):
       
    41     pass
       
    42 
    40 def ReIndentText(text, nb_spaces):
    43 def ReIndentText(text, nb_spaces):
    41     compute = ""
    44     compute = ""
    42     lines = text.splitlines()
    45     lines = text.splitlines()
    43     if len(lines) > 0:
    46     if len(lines) > 0:
    44         line_num = 0
    47         line_num = 0
   112         pou = currentProject.getpou(pou_name)
   115         pou = currentProject.getpou(pou_name)
   113         pou_type = pou.getpouType()
   116         pou_type = pou.getpouType()
   114         if pou_type in pouTypeNames:
   117         if pou_type in pouTypeNames:
   115             pou_program = PouProgram(pou.getname(), pouTypeNames[pou_type])
   118             pou_program = PouProgram(pou.getname(), pouTypeNames[pou_type])
   116         else:
   119         else:
   117             raise ValueError, "Undefined pou type"
   120             raise PLCGenException, "Undefined pou type"
   118         pou_program.GenerateInterface(pou.getinterface())
   121         pou_program.GenerateInterface(pou.getinterface())
   119         pou_program.GenerateConnectionTypes(pou)
   122         pou_program.GenerateConnectionTypes(pou)
   120         pou_program.GenerateProgram(pou)
   123         pou_program.GenerateProgram(pou)
   121         currentProgram += pou_program.GenerateSTProgram()
   124         currentProgram += pou_program.GenerateSTProgram()
   122 
   125 
   536                         connections = tmp_instance.connectionPointIn.getconnections()
   539                         connections = tmp_instance.connectionPointIn.getconnections()
   537                         if connections and len(connections) == 1:
   540                         if connections and len(connections) == 1:
   538                             expression = self.ComputeFBDExpression(body, connections[0], order)
   541                             expression = self.ComputeFBDExpression(body, connections[0], order)
   539                             self.ComputedConnectors[name] = expression
   542                             self.ComputedConnectors[name] = expression
   540                             return expression
   543                             return expression
   541             raise ValueError, "No connector found"
   544             raise PLCGenException, "No connector found"
   542 
   545 
   543     def GenerateLDPaths(self, connections, body):
   546     def GenerateLDPaths(self, connections, body):
   544         paths = []
   547         paths = []
   545         for connection in connections:
   548         for connection in connections:
   546             localId = connection.getrefLocalId()
   549             localId = connection.getrefLocalId()