PLCControler.py
changeset 483 779a519f78f2
parent 452 34fc9b813205
child 484 acef952101a5
equal deleted inserted replaced
482:4edbbab206a3 483:779a519f78f2
   873         varlist_list = []
   873         varlist_list = []
   874         current_varlist = None
   874         current_varlist = None
   875         current_type = None
   875         current_type = None
   876         for var in vars:
   876         for var in vars:
   877             next_type = (var["Class"], 
   877             next_type = (var["Class"], 
   878                                 var["Retain"], 
   878                          var["Option"], 
   879                                 var["Constant"], 
   879                          var["Location"] in ["", None] or 
   880                                 var["Location"] in ["", None] or 
   880                          # When declaring globals, located 
   881                                     # When declaring globals, located 
   881                          # and not located variables are 
   882                                     # and not located variables are 
   882                          # in the same declaration block
   883                                     # in the same declaration block
   883                          var["Class"] == "Global")
   884                                     var["Class"] == "Global")
       
   885             if current_type != next_type:
   884             if current_type != next_type:
   886                 current_type = next_type
   885                 current_type = next_type
   887                 infos = VAR_CLASS_INFOS.get(var["Class"], None)
   886                 infos = VAR_CLASS_INFOS.get(var["Class"], None)
   888                 if infos is not None:
   887                 if infos is not None:
   889                     current_varlist = infos[0]()
   888                     current_varlist = infos[0]()
   890                 else:
   889                 else:
   891                     current_varlist = plcopen.varList()
   890                     current_varlist = plcopen.varList()
   892                 varlist_list.append((var["Class"], current_varlist))
   891                 varlist_list.append((var["Class"], current_varlist))
   893                 if var["Retain"] == "Yes":
   892                 if var["Option"] == "Constant":
       
   893                     current_varlist.setconstant(True)
       
   894                 elif var["Option"] == "Retain":
   894                     current_varlist.setretain(True)
   895                     current_varlist.setretain(True)
   895                 if var["Constant"] == "Yes":
   896                 elif var["Option"] == "Non-Retain":
   896                     current_varlist.setconstant(True)
   897                     current_varlist.setnonretain(True)
   897             # Create variable and change its properties
   898             # Create variable and change its properties
   898             tempvar = plcopen.varListPlain_variable()
   899             tempvar = plcopen.varListPlain_variable()
   899             tempvar.setname(var["Name"])
   900             tempvar.setname(var["Name"])
   900 
   901 
   901             var_type = plcopen.dataType()
   902             var_type = plcopen.dataType()
   933         '''
   934         '''
   934         convert a PLC variable to the dictionary representation
   935         convert a PLC variable to the dictionary representation
   935         returned by Get*Vars)
   936         returned by Get*Vars)
   936         '''
   937         '''
   937 
   938 
   938         tempvar = {"Name" : var.getname()}
   939         tempvar = {"Name": var.getname()}
   939 
   940 
   940         vartype_content = var.gettype().getcontent()
   941         vartype_content = var.gettype().getcontent()
   941         if vartype_content["name"] == "derived":
   942         if vartype_content["name"] == "derived":
   942             tempvar["Type"] = vartype_content["value"].getname()
   943             tempvar["Type"] = vartype_content["value"].getname()
   943         elif vartype_content["name"] in ["string", "wstring"]:
   944         elif vartype_content["name"] in ["string", "wstring"]:
   957         if address:
   958         if address:
   958             tempvar["Location"] = address
   959             tempvar["Location"] = address
   959         else:
   960         else:
   960             tempvar["Location"] = ""
   961             tempvar["Location"] = ""
   961 
   962 
   962         if varlist.getretain():
   963         if varlist.getconstant():
   963             tempvar["Retain"] = "Yes"
   964             tempvar["Option"] = "Constant"
       
   965         elif varlist.getretain():
       
   966             tempvar["Option"] = "Retain"
       
   967         elif varlist.getnonretain():
       
   968             tempvar["Option"] = "Non-Retain"
   964         else:
   969         else:
   965             tempvar["Retain"] = "No"
   970             tempvar["Option"] = ""
   966 
       
   967         if varlist.getconstant():
       
   968             tempvar["Constant"] = "Yes"
       
   969         else:
       
   970             tempvar["Constant"] = "No"
       
   971 
   971 
   972         doc = var.getdocumentation()
   972         doc = var.getdocumentation()
   973         if doc:
   973         if doc:
   974             tempvar["Documentation"] = doc.gettext()
   974             tempvar["Documentation"] = doc.gettext()
   975         else:
   975         else: