845 if var["Constant"] == "Yes": |
845 if var["Constant"] == "Yes": |
846 current_varlist.setconstant(True) |
846 current_varlist.setconstant(True) |
847 # Create variable and change its properties |
847 # Create variable and change its properties |
848 tempvar = plcopen.varListPlain_variable() |
848 tempvar = plcopen.varListPlain_variable() |
849 tempvar.setname(var["Name"]) |
849 tempvar.setname(var["Name"]) |
|
850 |
850 var_type = plcopen.dataType() |
851 var_type = plcopen.dataType() |
851 if var["Type"] in self.GetBaseTypes(): |
852 if var["Type"] in self.GetBaseTypes(): |
852 if var["Type"] == "STRING": |
853 if var["Type"] == "STRING": |
853 var_type.setcontent({"name" : "string", "value" : plcopen.elementaryTypes_string()}) |
854 var_type.setcontent({"name" : "string", "value" : plcopen.elementaryTypes_string()}) |
854 elif var["Type"] == "WSTRING": |
855 elif var["Type"] == "WSTRING": |
858 else: |
859 else: |
859 derived_type = plcopen.derivedTypes_derived() |
860 derived_type = plcopen.derivedTypes_derived() |
860 derived_type.setname(var["Type"]) |
861 derived_type.setname(var["Type"]) |
861 var_type.setcontent({"name" : "derived", "value" : derived_type}) |
862 var_type.setcontent({"name" : "derived", "value" : derived_type}) |
862 tempvar.settype(var_type) |
863 tempvar.settype(var_type) |
|
864 |
863 if var["Initial Value"] != "": |
865 if var["Initial Value"] != "": |
864 value = plcopen.value() |
866 value = plcopen.value() |
865 value.setvalue(var["Initial Value"]) |
867 value.setvalue(var["Initial Value"]) |
866 tempvar.setinitialValue(value) |
868 tempvar.setinitialValue(value) |
867 if var["Location"] != "": |
869 if var["Location"] != "": |
868 tempvar.setaddress(var["Location"]) |
870 tempvar.setaddress(var["Location"]) |
869 else: |
871 else: |
870 tempvar.setaddress(None) |
872 tempvar.setaddress(None) |
|
873 if var['Documentation'] != "": |
|
874 ft = plcopen.formattedText() |
|
875 ft.settext(var['Documentation']) |
|
876 tempvar.setdocumentation(ft) |
|
877 |
871 # Add variable to varList |
878 # Add variable to varList |
872 current_varlist.appendvariable(tempvar) |
879 current_varlist.appendvariable(tempvar) |
873 return varlist_list |
880 return varlist_list |
|
881 |
|
882 def GetVariableDictionary(self, varlist, var): |
|
883 ''' |
|
884 convert a PLC variable to the dictionary representation |
|
885 returned by Get*Vars) |
|
886 ''' |
|
887 |
|
888 tempvar = {"Name" : var.getname()} |
|
889 |
|
890 vartype_content = var.gettype().getcontent() |
|
891 if vartype_content["name"] == "derived": |
|
892 tempvar["Type"] = vartype_content["value"].getname() |
|
893 elif vartype_content["name"] in ["string", "wstring"]: |
|
894 tempvar["Type"] = vartype_content["name"].upper() |
|
895 else: |
|
896 tempvar["Type"] = vartype_content["name"] |
|
897 |
|
898 tempvar["Edit"] = True |
|
899 |
|
900 initial = var.getinitialValue() |
|
901 if initial: |
|
902 tempvar["Initial Value"] = initial.getvalue() |
|
903 else: |
|
904 tempvar["Initial Value"] = "" |
|
905 |
|
906 address = var.getaddress() |
|
907 if address: |
|
908 tempvar["Location"] = address |
|
909 else: |
|
910 tempvar["Location"] = "" |
|
911 |
|
912 if varlist.getretain(): |
|
913 tempvar["Retain"] = "Yes" |
|
914 else: |
|
915 tempvar["Retain"] = "No" |
|
916 |
|
917 if varlist.getconstant(): |
|
918 tempvar["Constant"] = "Yes" |
|
919 else: |
|
920 tempvar["Constant"] = "No" |
|
921 |
|
922 doc = var.getdocumentation() |
|
923 if doc: |
|
924 tempvar["Documentation"] = doc.gettext() |
|
925 else: |
|
926 tempvar["Documentation"] = "" |
|
927 |
|
928 return tempvar |
874 |
929 |
875 # Replace the configuration globalvars by those given |
930 # Replace the configuration globalvars by those given |
876 def SetConfigurationGlobalVars(self, name, vars): |
931 def SetConfigurationGlobalVars(self, name, vars): |
877 if self.Project is not None: |
932 if self.Project is not None: |
878 # Found the configuration corresponding to name |
933 # Found the configuration corresponding to name |
892 configuration = project.getconfiguration(name) |
947 configuration = project.getconfiguration(name) |
893 if configuration is not None: |
948 if configuration is not None: |
894 # Extract variables from every varLists |
949 # Extract variables from every varLists |
895 for varlist in configuration.getglobalVars(): |
950 for varlist in configuration.getglobalVars(): |
896 for var in varlist.getvariable(): |
951 for var in varlist.getvariable(): |
897 tempvar = {"Name" : var.getname(), "Class" : "Global"} |
952 tempvar = self.GetVariableDictionary(varlist, var) |
898 vartype_content = var.gettype().getcontent() |
953 tempvar["Class"] = "Global" |
899 if vartype_content["name"] == "derived": |
|
900 tempvar["Type"] = vartype_content["value"].getname() |
|
901 elif vartype_content["name"] in ["string", "wstring"]: |
|
902 tempvar["Type"] = vartype_content["name"].upper() |
|
903 else: |
|
904 tempvar["Type"] = vartype_content["name"] |
|
905 tempvar["Edit"] = True |
|
906 initial = var.getinitialValue() |
|
907 if initial: |
|
908 tempvar["Initial Value"] = initial.getvalue() |
|
909 else: |
|
910 tempvar["Initial Value"] = "" |
|
911 address = var.getaddress() |
|
912 if address: |
|
913 tempvar["Location"] = address |
|
914 else: |
|
915 tempvar["Location"] = "" |
|
916 if varlist.getretain(): |
|
917 tempvar["Retain"] = "Yes" |
|
918 else: |
|
919 tempvar["Retain"] = "No" |
|
920 if varlist.getconstant(): |
|
921 tempvar["Constant"] = "Yes" |
|
922 else: |
|
923 tempvar["Constant"] = "No" |
|
924 vars.append(tempvar) |
954 vars.append(tempvar) |
925 return vars |
955 return vars |
926 |
956 |
927 # Replace the resource globalvars by those given |
957 # Replace the resource globalvars by those given |
928 def SetConfigurationResourceGlobalVars(self, config_name, name, vars): |
958 def SetConfigurationResourceGlobalVars(self, config_name, name, vars): |
944 resource = project.getconfigurationResource(config_name, name) |
974 resource = project.getconfigurationResource(config_name, name) |
945 if resource: |
975 if resource: |
946 # Extract variables from every varLists |
976 # Extract variables from every varLists |
947 for varlist in resource.getglobalVars(): |
977 for varlist in resource.getglobalVars(): |
948 for var in varlist.getvariable(): |
978 for var in varlist.getvariable(): |
949 tempvar = {"Name" : var.getname(), "Class" : "Global"} |
979 tempvar = self.GetVariableDictionary(varlist, var) |
950 vartype_content = var.gettype().getcontent() |
980 tempvar["Class"] = "Global" |
951 if vartype_content["name"] == "derived": |
|
952 tempvar["Type"] = vartype_content["value"].getname() |
|
953 elif vartype_content["name"] in ["string", "wstring"]: |
|
954 tempvar["Type"] = vartype_content["name"].upper() |
|
955 else: |
|
956 tempvar["Type"] = vartype_content["name"] |
|
957 tempvar["Edit"] = True |
|
958 initial = var.getinitialValue() |
|
959 if initial: |
|
960 tempvar["Initial Value"] = initial.getvalue() |
|
961 else: |
|
962 tempvar["Initial Value"] = "" |
|
963 address = var.getaddress() |
|
964 if address: |
|
965 tempvar["Location"] = address |
|
966 else: |
|
967 tempvar["Location"] = "" |
|
968 if varlist.getretain(): |
|
969 tempvar["Retain"] = "Yes" |
|
970 else: |
|
971 tempvar["Retain"] = "No" |
|
972 if varlist.getconstant(): |
|
973 tempvar["Constant"] = "Yes" |
|
974 else: |
|
975 tempvar["Constant"] = "No" |
|
976 vars.append(tempvar) |
981 vars.append(tempvar) |
977 return vars |
982 return vars |
978 |
983 |
979 # Recursively generate element name tree for a structured variable |
984 # Recursively generate element name tree for a structured variable |
980 def GenerateVarTree(self, typename, debug = False): |
985 def GenerateVarTree(self, typename, debug = False): |
1009 tree.append((element.getname(), element_type["value"].getname(), self.GenerateVarTree(element_type["value"].getname()))) |
1014 tree.append((element.getname(), element_type["value"].getname(), self.GenerateVarTree(element_type["value"].getname()))) |
1010 else: |
1015 else: |
1011 tree.append((element.getname(), element_type["name"], ([], []))) |
1016 tree.append((element.getname(), element_type["name"], ([], []))) |
1012 return tree, [] |
1017 return tree, [] |
1013 return [], [] |
1018 return [], [] |
1014 |
1019 |
1015 # Return the interface for the given pou |
1020 # Return the interface for the given pou |
1016 def GetPouInterfaceVars(self, pou, debug = False): |
1021 def GetPouInterfaceVars(self, pou, debug = False): |
1017 vars = [] |
1022 vars = [] |
1018 # Verify that the pou has an interface |
1023 # Verify that the pou has an interface |
1019 if pou.interface is not None: |
1024 if pou.interface is not None: |
1020 # Extract variables from every varLists |
1025 # Extract variables from every varLists |
1021 for type, varlist in pou.getvars(): |
1026 for type, varlist in pou.getvars(): |
1022 for var in varlist.getvariable(): |
1027 for var in varlist.getvariable(): |
1023 tempvar = {"Name" : var.getname(), "Class" : type, "Tree" : ([], [])} |
1028 tempvar = self.GetVariableDictionary(varlist, var) |
|
1029 |
|
1030 tempvar["Class"] = type |
|
1031 tempvar["Tree"] = ([], []) |
|
1032 |
1024 vartype_content = var.gettype().getcontent() |
1033 vartype_content = var.gettype().getcontent() |
1025 if vartype_content["name"] == "derived": |
1034 if vartype_content["name"] == "derived": |
1026 tempvar["Type"] = vartype_content["value"].getname() |
|
1027 tempvar["Edit"] = not pou.hasblock(tempvar["Name"]) |
1035 tempvar["Edit"] = not pou.hasblock(tempvar["Name"]) |
1028 tempvar["Tree"] = self.GenerateVarTree(tempvar["Type"], debug) |
1036 tempvar["Tree"] = self.GenerateVarTree(tempvar["Type"], debug) |
1029 else: |
1037 |
1030 if vartype_content["name"] in ["string", "wstring"]: |
|
1031 tempvar["Type"] = vartype_content["name"].upper() |
|
1032 else: |
|
1033 tempvar["Type"] = vartype_content["name"] |
|
1034 tempvar["Edit"] = True |
|
1035 initial = var.getinitialValue() |
|
1036 if initial: |
|
1037 tempvar["Initial Value"] = initial.getvalue() |
|
1038 else: |
|
1039 tempvar["Initial Value"] = "" |
|
1040 address = var.getaddress() |
|
1041 if address: |
|
1042 tempvar["Location"] = address |
|
1043 else: |
|
1044 tempvar["Location"] = "" |
|
1045 if varlist.getretain(): |
|
1046 tempvar["Retain"] = "Yes" |
|
1047 else: |
|
1048 tempvar["Retain"] = "No" |
|
1049 if varlist.getconstant(): |
|
1050 tempvar["Constant"] = "Yes" |
|
1051 else: |
|
1052 tempvar["Constant"] = "No" |
|
1053 vars.append(tempvar) |
1038 vars.append(tempvar) |
1054 return vars |
1039 return vars |
1055 |
1040 |
1056 # Replace the Pou interface by the one given |
1041 # Replace the Pou interface by the one given |
1057 def SetPouInterfaceVars(self, name, vars): |
1042 def SetPouInterfaceVars(self, name, vars): |