--- a/PLCGenerator.py Tue Jul 10 11:59:28 2007 +0200
+++ b/PLCGenerator.py Tue Jul 10 14:24:19 2007 +0200
@@ -66,7 +66,7 @@
def IsAlreadyDefined(self, name):
for list_type, retain, constant, vars in self.Interface:
- for var_type, var_name, var_initial in vars:
+ for var_type, var_name, var_address, var_initial in vars:
if name == var_name:
return True
return False
@@ -83,7 +83,10 @@
initial_value = initial.getValue()
else:
initial_value = None
- variables.append((type, var.getName(), initial_value))
+ address = var.getAddress()
+ if address == "":
+ address = None
+ variables.append((type, var.getName(), address, initial_value))
self.Interface.append((varTypeNames[varlist["name"]], varlist["value"].getRetain(),
varlist["value"].getConstant(), variables))
@@ -143,7 +146,7 @@
if self.Interface[-1][0] != "VAR" or self.Interface[-1][1] or self.Interface[-1][2]:
self.Interface.append(("VAR", False, False, []))
if not self.IsAlreadyDefined(name):
- self.Interface[-1][3].append((type, name, None))
+ self.Interface[-1][3].append((type, name, None, None))
vars = []
for variable in instance.inputVariables.getVariable():
connections = variable.connectionPointIn.getConnections()
@@ -433,7 +436,7 @@
while self.IsAlreadyDefined(name):
i += 1
name = "%s%d"%(edge, i)
- self.Interface[-1][3].append((edge, name, None))
+ self.Interface[-1][3].append((edge, name, None, None))
self.Program += " %s(CLK := %s);\n"%(name, text)
return "%s.Q"%name
@@ -449,11 +452,14 @@
if constant:
program += " CONSTANT"
program += "\n"
- for var_type, var_name, var_initial in variables:
+ for var_type, var_name, var_address, var_initial in variables:
+ program += " %s "%var_name
+ if var_address != None:
+ program += "AT %s "%address
+ program += ": %s"%var_type
if var_initial != None:
- program += " %s : %s := %s;\n"%(var_name, var_type, {"TRUE":"0","FALSE":"1"}.get(str(var_initial).upper(),str(var_initial)))
- else:
- program += " %s : %s;\n"%(var_name, var_type)
+ program += " := %s"%{"TRUE":"0","FALSE":"1"}.get(str(var_initial).upper(), str(var_initial))
+ program += ";\n"
program += " END_VAR\n"
program += "\n"
program += self.Program
@@ -470,17 +476,16 @@
config += " CONSTANT"
config += "\n"
for var in varlist.getVariable():
- var_type = var.getType().getValue()
- var_name = var.getName()
+ config += " %s "%var.getName()
+ address = var.getAddress()
+ if address:
+ config += "AT %s "%address
+ config += ": %s"%var.getType().getValue()
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)
+ value = str(initial.getValue())
+ config += " := %s"%{"TRUE":"0","FALSE":"1"}.get(value.upper(), value)
+ config += ";\n"
config += " END_VAR\n"
for resource in configuration.getResource():
config += self.GenerateResource(resource)
@@ -497,45 +502,44 @@
resrce += " CONSTANT"
resrce += "\n"
for var in varlist.getVariable():
- var_type = var.getType().getValue()
- var_name = var.getName()
+ resrce += " %s "%var.getName()
+ address = var.getAddress()
+ if address:
+ resrce += "AT %s "%address
+ resrce += ": %s"%var.getType().getValue()
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)
+ value = str(initial.getValue())
+ resrce += " := %s"%{"TRUE":"0","FALSE":"1"}.get(value.upper(), value)
+ resrce += ";\n"
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"
+ 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