# HG changeset patch # User lbessard # Date 1184087368 -7200 # Node ID 0dd4a876392feff4ac407c9985f2b16366d157bf # Parent cf9efccff00989c698d27f778b2adeed9b223b29 Bugs on ST generation fixed diff -r cf9efccff009 -r 0dd4a876392f PLCControler.py --- a/PLCControler.py Tue Jul 10 17:30:41 2007 +0200 +++ b/PLCControler.py Tue Jul 10 19:09:28 2007 +0200 @@ -556,8 +556,8 @@ current_varlist = None current_type = None for var in vars: - if current_type != (var["Class"], var["Retain"], var["Constant"]): - current_type = (var["Class"], var["Retain"], var["Constant"]) + if current_type != (var["Class"], var["Retain"], var["Constant"], var["Location"] != ""): + current_type = (var["Class"], var["Retain"], var["Constant"], var["Location"] != "") current_varlist = plcopen.varList() varlist_list.append((var["Class"], current_varlist)) if var["Retain"] == "Yes": diff -r cf9efccff009 -r 0dd4a876392f PLCGenerator.py --- a/PLCGenerator.py Tue Jul 10 17:30:41 2007 +0200 +++ b/PLCGenerator.py Tue Jul 10 19:09:28 2007 +0200 @@ -65,7 +65,7 @@ self.Program = "" def IsAlreadyDefined(self, name): - for list_type, retain, constant, vars in self.Interface: + for list_type, retain, constant, located, vars in self.Interface: for var_type, var_name, var_address, var_initial in vars: if name == var_name: return True @@ -76,6 +76,7 @@ self.ReturnType = interface.getReturnType().getValue() for varlist in interface.getContent(): variables = [] + located = False for var in varlist["value"].getVariable(): type = var.getType().getValue() initial = var.getInitialValue() @@ -86,9 +87,11 @@ address = var.getAddress() if address == "": address = None + else: + located = True variables.append((type, var.getName(), address, initial_value)) self.Interface.append((varTypeNames[varlist["name"]], varlist["value"].getRetain(), - varlist["value"].getConstant(), variables)) + varlist["value"].getConstant(), located, variables)) def GenerateProgram(self, pou): body = pou.getBody() @@ -143,10 +146,10 @@ variable = instance.outputVariables.getVariable()[0] return self.ExtractModifier(variable, "%s(%s)"%(type, ", ".join(vars))) elif block_infos["type"] == "functionBlock": - if self.Interface[-1][0] != "VAR" or self.Interface[-1][1] or self.Interface[-1][2]: - self.Interface.append(("VAR", False, False, [])) + if self.Interface[-1][0] != "VAR" or self.Interface[-1][1] or self.Interface[-1][2] or self.Interface[-1][3]: + self.Interface.append(("VAR", False, False, False, [])) if not self.IsAlreadyDefined(name): - self.Interface[-1][3].append((type, name, None, None)) + self.Interface[-1][4].append((type, name, None, None)) vars = [] for variable in instance.inputVariables.getVariable(): connections = variable.connectionPointIn.getConnections() @@ -429,14 +432,14 @@ return text def AddTrigger(self, edge, text): - if self.Interface[-1][0] != "VAR" or self.Interface[-1][1] or self.Interface[-1][2]: - self.Interface.append(("VAR", False, False, [])) + if self.Interface[-1][0] != "VAR" or self.Interface[-1][1] or self.Interface[-1][2] or self.Interface[-1][3]: + self.Interface.append(("VAR", False, False, False, [])) i = 1 name = "%s%d"%(edge, i) while self.IsAlreadyDefined(name): i += 1 name = "%s%d"%(edge, i) - self.Interface[-1][3].append((edge, name, None, None)) + self.Interface[-1][4].append((edge, name, None, None)) self.Program += " %s(CLK := %s);\n"%(name, text) return "%s.Q"%name @@ -445,7 +448,7 @@ program = "%s %s : %s\n"%(self.Type, self.Name, self.ReturnType) else: program = "%s %s\n"%(self.Type, self.Name) - for list_type, retain, constant, variables in self.Interface: + for list_type, retain, constant, located, variables in self.Interface: program += " %s"%list_type if retain: program += " RETAIN" @@ -458,7 +461,11 @@ program += "AT %s "%var_address program += ": %s"%var_type if var_initial != None: - program += " := %s"%{"TRUE":"0","FALSE":"1"}.get(str(var_initial).upper(), str(var_initial)) + value = {"TRUE":"0","FALSE":"1"}.get(str(var_initial).upper(), str(var_initial)) + if var_type in ["STRING", "WSTRING"]: + program += " := \"%s\""%value + else: + program += " := %s"%value program += ";\n" program += " END_VAR\n" program += "\n" @@ -476,15 +483,20 @@ config += " CONSTANT" config += "\n" for var in varlist.getVariable(): - config += " %s "%var.getName() + var_type = var.getType().getValue() + config += " %s "%var.getName() address = var.getAddress() if address: config += "AT %s "%address - config += ": %s"%var.getType().getValue() + config += ": %s"%var_type initial = var.getInitialValue() if initial: value = str(initial.getValue()) - config += " := %s"%{"TRUE":"0","FALSE":"1"}.get(value.upper(), value) + value = {"TRUE":"0","FALSE":"1"}.get(value.upper(), value) + if var_type in ["STRING", "WSTRING"]: + config += " := \"%s\""%value + else: + config += " := %s"%value config += ";\n" config += " END_VAR\n" for resource in configuration.getResource(): @@ -493,7 +505,7 @@ return config def GenerateResource(self, resource): - resrce = "\n RESOURCE %s\n"%resource.getName() + resrce = "\n RESOURCE %s ON BEREMIZ\n"%resource.getName() for varlist in resource.getGlobalVars(): resrce += " VAR_GLOBAL" if varlist.getRetain(): @@ -502,6 +514,7 @@ resrce += " CONSTANT" resrce += "\n" for var in varlist.getVariable(): + var_type = var.getType().getValue() resrce += " %s "%var.getName() address = var.getAddress() if address: @@ -510,7 +523,11 @@ initial = var.getInitialValue() if initial: value = str(initial.getValue()) - resrce += " := %s"%{"TRUE":"0","FALSE":"1"}.get(value.upper(), value) + value = {"TRUE":"0","FALSE":"1"}.get(value.upper(), value) + if var_type in ["STRING", "WSTRING"]: + resrce += " := \"%s\""%value + else: + resrce += " := %s"%value resrce += ";\n" resrce += " END_VAR\n" tasks = resource.getTask()