PLCGenerator.py
changeset 93 c3c24b979a4d
parent 80 c798a68c5560
child 104 a9b8916d906d
equal deleted inserted replaced
92:76d5001393df 93:c3c24b979a4d
   196             for var in varlist["value"].getVariable():
   196             for var in varlist["value"].getVariable():
   197                 type = var.getType().getValue()
   197                 type = var.getType().getValue()
   198                 if not isinstance(type, (StringType, UnicodeType)):
   198                 if not isinstance(type, (StringType, UnicodeType)):
   199                     type = type.getName()
   199                     type = type.getName()
   200                     GeneratePouProgram(type)
   200                     GeneratePouProgram(type)
   201                 initial = var.getInitialValue()
   201                     blocktype = GetBlockType(type)
   202                 if initial:
   202                     if blocktype:
   203                     initial_value = initial.getValue()
   203                         variables.extend(blocktype["initialise"](type, var.getName()))
       
   204                         located = False
   204                 else:
   205                 else:
   205                     initial_value = None
   206                     initial = var.getInitialValue()
   206                 address = var.getAddress()
   207                     if initial:
   207                 if address:
   208                         initial_value = initial.getValue()
   208                     located = True
   209                     else:
   209                 variables.append((type, var.getName(), address, initial_value))
   210                         initial_value = None
   210             self.Interface.append((varTypeNames[varlist["name"]], varlist["value"].getRetain(), 
   211                     address = var.getAddress()
       
   212                     if address:
       
   213                         located = True
       
   214                     variables.append((type, var.getName(), address, initial_value))
       
   215             if len(variables) > 0:
       
   216                 self.Interface.append((varTypeNames[varlist["name"]], varlist["value"].getRetain(), 
   211                             varlist["value"].getConstant(), located, variables))
   217                             varlist["value"].getConstant(), located, variables))
   212     
   218     
   213     def GenerateProgram(self, pou):
   219     def GenerateProgram(self, pou):
   214         body = pou.getBody()
   220         body = pou.getBody()
   215         body_content = body.getContent()
   221         body_content = body.getContent()
   620                 program += " RETAIN"
   626                 program += " RETAIN"
   621             if constant:
   627             if constant:
   622                 program += " CONSTANT"
   628                 program += " CONSTANT"
   623             program += "\n"
   629             program += "\n"
   624             for var_type, var_name, var_address, var_initial in variables:
   630             for var_type, var_name, var_address, var_initial in variables:
   625                 program += "    %s "%var_name
   631                 program += "    "
       
   632                 if var_name:
       
   633                     program += "%s "%var_name
   626                 if var_address != None:
   634                 if var_address != None:
   627                     program += "AT %s "%var_address
   635                     program += "AT %s "%var_address
   628                 program += ": %s"%var_type
   636                 program += ": %s"%var_type
   629                 if var_initial != None:
   637                 if var_initial != None:
   630                     value = {"TRUE":"0","FALSE":"1"}.get(str(var_initial).upper(), str(var_initial))
   638                     value = {"TRUE":"0","FALSE":"1"}.get(str(var_initial).upper(), str(var_initial))