# HG changeset patch # User lbessard # Date 1184061568 -7200 # Node ID 3b7e23a323a6312de69f53a6cdc656b5f156054f # Parent fc23e1f415d87033f346036d98eddb023e137bac Adding support for configuration generation diff -r fc23e1f415d8 -r 3b7e23a323a6 PLCControler.py --- a/PLCControler.py Tue Jul 10 09:52:53 2007 +0200 +++ b/PLCControler.py Tue Jul 10 11:59:28 2007 +0200 @@ -798,11 +798,11 @@ blocktypes = [] for category in BlockTypes[:-1]: for blocktype in category["list"]: - if blocktype["type"] != "function": + if blocktype["type"] == "program": blocktypes.append(blocktype["name"]) if self.Project: for pou in self.Project.getPous(): - if pou.pouType.getValue() != "function": + if pou.pouType.getValue() == "program": blocktypes.append(pou.getName()) return blocktypes diff -r fc23e1f415d8 -r 3b7e23a323a6 PLCGenerator.py --- a/PLCGenerator.py Tue Jul 10 09:52:53 2007 +0200 +++ b/PLCGenerator.py Tue Jul 10 11:59:28 2007 +0200 @@ -438,11 +438,10 @@ return "%s.Q"%name def GenerateSTProgram(self): - program = "" if self.ReturnType: - program += "%s %s : %s\n"%(self.Type, self.Name, self.ReturnType) + program = "%s %s : %s\n"%(self.Type, self.Name, self.ReturnType) else: - program += "%s %s\n"%(self.Type, self.Name) + program = "%s %s\n"%(self.Type, self.Name) for list_type, retain, constant, variables in self.Interface: program += " %s"%list_type if retain: @@ -461,6 +460,85 @@ program += "END_%s\n\n"%self.Type return program + def GenerateConfiguration(self, configuration): + config = "\nCONFIGURATION %s\n"%configuration.getName() + for varlist in configuration.getGlobalVars(): + config += " VAR_GLOBAL" + if varlist.getRetain(): + config += " RETAIN" + if varlist.getConstant(): + config += " CONSTANT" + config += "\n" + for var in varlist.getVariable(): + var_type = var.getType().getValue() + var_name = var.getName() + initial = var.getInitialValue() + if initial: + var_initial = initial.getValue() + else: + var_initial = None + if var_initial != None: + config += " %s : %s := %s;\n"%(var_name, var_type, {"TRUE":"0","FALSE":"1"}.get(str(var_initial).upper(),str(var_initial))) + else: + config += " %s : %s;\n"%(var_name, var_type) + config += " END_VAR\n" + for resource in configuration.getResource(): + config += self.GenerateResource(resource) + config += "END_CONFIGURATION\n" + return config + + def GenerateResource(self, resource): + resrce = "\n RESOURCE %s\n"%resource.getName() + for varlist in resource.getGlobalVars(): + resrce += " VAR_GLOBAL" + if varlist.getRetain(): + resrce += " RETAIN" + if varlist.getConstant(): + resrce += " CONSTANT" + resrce += "\n" + for var in varlist.getVariable(): + var_type = var.getType().getValue() + var_name = var.getName() + initial = var.getInitialValue() + if initial: + var_initial = initial.getValue() + else: + var_initial = None + if var_initial != None: + resrce += " %s : %s := %s;\n"%(var_name, var_type, {"TRUE":"0","FALSE":"1"}.get(str(var_initial).upper(),str(var_initial))) + else: + resrce += " %s : %s;\n"%(var_name, var_type) + resrce += " END_VAR\n" + tasks = resource.getTask() + for task in tasks: + resrce += " TASK %s("%task.getName() + args = [] + single = task.getSingle() + if single: + args.append("SINGLE := %s"%single) + interval = task.getInterval() + if interval: + text = "t#" + if interval.hour != 0: + text += "%dh"%interval.hour + if interval.minute != 0: + text += "%dm"%interval.minute + if interval.second != 0: + text += "%ds"%interval.second + if interval.microsecond != 0: + text += "%dms"%(interval.microsecond / 1000) + args.append("INTERVAL := %s"%text) + args.append("PRIORITY := %s"%str(task.priority.getValue())) + resrce += ",".join(args) + ");\n" + for task in tasks: + for instance in task.getPouInstance(): + resrce += " PROGRAM %s WITH %s : %s;\n"%(instance.getName(), task.getName(), instance.getType()) + for instance in resource.getPouInstance(): + resrce += " PROGRAM %s : %s;\n"%(instance.getName(), instance.getType()) + resrce += " END_RESOURCE\n" + return resrce + + def GenerateCurrentProgram(project): program = "" for pou in project.getPous(): @@ -472,5 +550,7 @@ pou_program.GenerateInterface(pou.getInterface()) pou_program.GenerateProgram(pou) program += pou_program.GenerateSTProgram() + for config in project.getConfigurations(): + program += pou_program.GenerateConfiguration(config) return program