# HG changeset patch # User lbessard # Date 1223906872 -7200 # Node ID a18ddbbc5c5816761bd8f929bce2ccfe4f02830c # Parent eb49f3f511ccf97895410d31f2bc2b412e63b8f0 Bugs on pous without interface fixed diff -r eb49f3f511cc -r a18ddbbc5c58 plcopen/plcopen.py --- a/plcopen/plcopen.py Wed Oct 01 18:16:33 2008 +0200 +++ b/plcopen/plcopen.py Mon Oct 13 16:07:52 2008 +0200 @@ -780,21 +780,26 @@ def getvars(self): vars = [] - reverse_types = {} - for name, value in VarTypes.items(): - reverse_types[value] = name - for varlist in self.interface.getcontent(): - vars.append((reverse_types[varlist["name"]], varlist["value"])) + if self.interface is not None: + reverse_types = {} + for name, value in VarTypes.items(): + reverse_types[value] = name + for varlist in self.interface.getcontent(): + vars.append((reverse_types[varlist["name"]], varlist["value"])) return vars setattr(cls, "getvars", getvars) def setvars(self, vars): + if self.interface is None: + self.interface = PLCOpenClasses["pou_interface"]() self.interface.setcontent([]) for vartype, varlist in vars: self.interface.appendcontent({"name" : VarTypes[vartype], "value" : varlist}) setattr(cls, "setvars", setvars) def addpouVar(self, type, name): + if self.interface is None: + self.interface = PLCOpenClasses["pou_interface"]() content = self.interface.getcontent() if len(content) == 0 or content[-1]["name"] != "localVars": content.append({"name" : "localVars", "value" : PLCOpenClasses["interface_localVars"]()}) @@ -814,31 +819,33 @@ setattr(cls, "addpouVar", addpouVar) def changepouVar(self, old_type, old_name, new_type, new_name): - content = self.interface.getcontent() - for varlist in content: - variables = varlist["value"].getvariable() - for var in variables: - if var.getname() == old_name: - vartype_content = var.gettype().getcontent() - if vartype_content["name"] == "derived" and vartype_content["value"].getname() == old_type: - var.setname(new_name) - vartype_content["value"].setname(new_type) - return + if self.interface is not None: + content = self.interface.getcontent() + for varlist in content: + variables = varlist["value"].getvariable() + for var in variables: + if var.getname() == old_name: + vartype_content = var.gettype().getcontent() + if vartype_content["name"] == "derived" and vartype_content["value"].getname() == old_type: + var.setname(new_name) + vartype_content["value"].setname(new_type) + return setattr(cls, "changepouVar", changepouVar) def removepouVar(self, type, name): - content = self.interface.getcontent() - for varlist in content: - variables = varlist["value"].getvariable() - for var in variables: - if var.getname() == name: - vartype_content = var.gettype().getcontent() - if vartype_content["name"] == "derived" and vartype_content["value"].getname() == type: - variables.remove(var) - break - if len(varlist["value"].getvariable()) == 0: - content.remove(varlist) - break + if self.interface is not None: + content = self.interface.getcontent() + for varlist in content: + variables = varlist["value"].getvariable() + for var in variables: + if var.getname() == name: + vartype_content = var.gettype().getcontent() + if vartype_content["name"] == "derived" and vartype_content["value"].getname() == type: + variables.remove(var) + break + if len(varlist["value"].getvariable()) == 0: + content.remove(varlist) + break setattr(cls, "removepouVar", removepouVar) def hasblock(self, name):