author | lbessard |
Mon, 09 Jul 2007 11:10:14 +0200 | |
changeset 27 | dae55dd9ee14 |
parent 6 | c8cf918ee7ea |
child 28 | fc23e1f415d8 |
permissions | -rw-r--r-- |
0 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
4 |
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor |
|
5 |
#based on the plcopen standard. |
|
6 |
# |
|
7 |
#Copyright (C): Edouard TISSERANT and Laurent BESSARD |
|
8 |
# |
|
9 |
#See COPYING file for copyrights details. |
|
10 |
# |
|
11 |
#This library is free software; you can redistribute it and/or |
|
5 | 12 |
#modify it under the terms of the GNU General Public |
0 | 13 |
#License as published by the Free Software Foundation; either |
14 |
#version 2.1 of the License, or (at your option) any later version. |
|
15 |
# |
|
16 |
#This library is distributed in the hope that it will be useful, |
|
17 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
19 |
#Lesser General Public License for more details. |
|
20 |
# |
|
5 | 21 |
#You should have received a copy of the GNU General Public |
0 | 22 |
#License along with this library; if not, write to the Free Software |
23 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 |
||
25 |
from plcopen import plcopen |
|
26 |
from plcopen.structures import * |
|
27 |
from types import * |
|
28 |
||
29 |
varTypeNames = {"localVars" : "VAR", "tempVars" : "VAR_TEMP", "inputVars" : "VAR_INPUT", |
|
30 |
"outputVars" : "VAR_OUTPUT", "inOutVars" : "VAR_IN_OUT", "externalVars" : "VAR_EXTERNAL", |
|
31 |
"globalVars" : "VAR_GLOBAL", "accessVars" : "VAR_ACCESS"} |
|
1 | 32 |
|
6 | 33 |
pouTypeNames = {"function" : "FUNCTION", "functionBlock" : "FUNCTION_BLOCK", "program" : "PROGRAM"} |
34 |
||
1 | 35 |
def ReIndentText(text, nb_spaces): |
36 |
compute = "" |
|
37 |
lines = text.splitlines() |
|
38 |
if len(lines) > 0: |
|
39 |
spaces = 0 |
|
40 |
while lines[0][spaces] == " ": |
|
41 |
spaces += 1 |
|
42 |
indent = "" |
|
43 |
for i in xrange(spaces, nb_spaces): |
|
44 |
indent += " " |
|
45 |
for line in lines: |
|
2 | 46 |
if line != "": |
47 |
compute += "%s%s\n"%(indent, line) |
|
48 |
else: |
|
49 |
compute += "\n" |
|
1 | 50 |
return compute |
51 |
||
0 | 52 |
""" |
53 |
Module implementing methods for generating PLC programs in ST or IL |
|
54 |
""" |
|
55 |
||
56 |
class PouProgram: |
|
57 |
||
58 |
def __init__(self, name, type): |
|
59 |
self.Name = name |
|
60 |
self.Type = type |
|
1 | 61 |
self.ReturnType = None |
62 |
self.Interface = [] |
|
63 |
self.InitialSteps = [] |
|
64 |
self.SFCNetworks = {"Steps":{}, "Transitions":{}, "Actions":{}} |
|
0 | 65 |
self.Program = "" |
66 |
||
1 | 67 |
def IsAlreadyDefined(self, name): |
68 |
for list_type, retain, constant, vars in self.Interface: |
|
69 |
for var_type, var_name in vars: |
|
70 |
if name == var_name: |
|
71 |
return True |
|
72 |
return False |
|
73 |
||
0 | 74 |
def GenerateInterface(self, interface): |
75 |
if self.Type == "FUNCTION": |
|
1 | 76 |
self.ReturnType = interface.getReturnType().getValue() |
0 | 77 |
for varlist in interface.getContent(): |
1 | 78 |
variables = [] |
0 | 79 |
for var in varlist["value"].getVariable(): |
80 |
type = var.getType().getValue() |
|
1 | 81 |
variables.append((type, var.getName())) |
82 |
self.Interface.append((varTypeNames[varlist["name"]], varlist["value"].getRetain(), |
|
83 |
varlist["value"].getConstant(), variables)) |
|
0 | 84 |
|
85 |
def GenerateProgram(self, pou): |
|
86 |
body = pou.getBody() |
|
87 |
body_content = body.getContent() |
|
88 |
body_type = body_content["name"] |
|
89 |
if body_type in ["IL","ST"]: |
|
1 | 90 |
self.Program = ReIndentText(body_content["value"].getText(), 2) |
0 | 91 |
elif body_type == "FBD": |
92 |
for instance in body.getContentInstances(): |
|
93 |
if isinstance(instance, plcopen.outVariable): |
|
94 |
var = instance.getExpression() |
|
95 |
connections = instance.connectionPointIn.getConnections() |
|
96 |
if connections and len(connections) == 1: |
|
97 |
expression = self.ComputeFBDExpression(body, connections[0]) |
|
98 |
self.Program += " %s := %s;\n"%(var, expression) |
|
99 |
elif body_type == "LD": |
|
100 |
for instance in body.getContentInstances(): |
|
101 |
if isinstance(instance, plcopen.coil): |
|
102 |
paths = self.GenerateLDPaths(instance, body) |
|
103 |
variable = self.ExtractModifier(instance, instance.getVariable()) |
|
104 |
expression = self.ComputeLDExpression(paths, True) |
|
105 |
self.Program += " %s := %s;\n"%(variable, expression) |
|
106 |
elif body_type == "SFC": |
|
107 |
for instance in body.getContentInstances(): |
|
108 |
if isinstance(instance, plcopen.step): |
|
1 | 109 |
self.GenerateSFCStep(instance, pou) |
0 | 110 |
elif isinstance(instance, plcopen.actionBlock): |
1 | 111 |
self.GenerateSFCStepActions(instance, pou) |
0 | 112 |
elif isinstance(instance, plcopen.transition): |
1 | 113 |
self.GenerateSFCTransition(instance, pou) |
0 | 114 |
elif isinstance(instance, plcopen.jumpStep): |
115 |
self.GenerateSFCJump(instance, pou) |
|
1 | 116 |
for initialstep in self.InitialSteps: |
117 |
self.ComputeSFCStep(initialstep) |
|
0 | 118 |
|
119 |
def ComputeFBDExpression(self, body, link): |
|
120 |
localid = link.getRefLocalId() |
|
121 |
instance = body.getContentInstance(localid) |
|
122 |
if isinstance(instance, plcopen.inVariable): |
|
123 |
return instance.getExpression() |
|
124 |
elif isinstance(instance, plcopen.block): |
|
125 |
name = instance.getInstanceName() |
|
126 |
type = instance.getTypeName() |
|
127 |
block_infos = GetBlockType(type) |
|
128 |
if block_infos["type"] == "function": |
|
129 |
vars = [] |
|
130 |
for variable in instance.inputVariables.getVariable(): |
|
131 |
connections = variable.connectionPointIn.getConnections() |
|
132 |
if connections and len(connections) == 1: |
|
133 |
value = self.ComputeFBDExpression(body, connections[0]) |
|
134 |
vars.append(self.ExtractModifier(variable, value)) |
|
135 |
variable = instance.outputVariables.getVariable()[0] |
|
136 |
return self.ExtractModifier(variable, "%s(%s)"%(type, ", ".join(vars))) |
|
137 |
elif block_infos["type"] == "functionBlock": |
|
1 | 138 |
if self.Interface[-1][0] != "VAR" or self.Interface[-1][1] or self.Interface[-1][2]: |
139 |
self.Interface.append(("VAR", False, False, [])) |
|
140 |
if not self.IsAlreadyDefined(name): |
|
141 |
self.Interface[-1][3].append((type, name)) |
|
0 | 142 |
vars = [] |
143 |
for variable in instance.inputVariables.getVariable(): |
|
144 |
connections = variable.connectionPointIn.getConnections() |
|
145 |
if connections and len(connections) == 1: |
|
146 |
parameter = variable.getFormalParameter() |
|
147 |
value = self.ComputeFBDExpression(body, connections[0]) |
|
148 |
vars.append(self.ExtractModifier(variable, "%s := %s"%(parameter, value))) |
|
149 |
self.Program += " %s(%s);\n"%(name, ", ".join(vars)) |
|
150 |
connectionPoint = link.getPosition()[-1] |
|
151 |
for variable in instance.outputVariables.getVariable(): |
|
152 |
blockPointx, blockPointy = variable.connectionPointOut.getRelPosition() |
|
153 |
if instance.getX() + blockPointx == connectionPoint.getX() and instance.getY() + blockPointy == connectionPoint.getY(): |
|
154 |
return self.ExtractModifier(variable, "%s.%s"%(name, variable.getFormalParameter())) |
|
155 |
raise ValueError, "No output variable found" |
|
156 |
||
157 |
def GenerateLDPaths(self, instance, body): |
|
158 |
paths = [] |
|
159 |
variable = self.ExtractModifier(instance, instance.getVariable()) |
|
160 |
connections = instance.connectionPointIn.getConnections() |
|
161 |
for connection in connections: |
|
162 |
localId = connection.getRefLocalId() |
|
163 |
next = body.getContentInstance(localId) |
|
164 |
if isinstance(next, plcopen.leftPowerRail): |
|
165 |
paths.append(None) |
|
166 |
else: |
|
167 |
paths.append(self.GenerateLDPaths(next, body)) |
|
168 |
if isinstance(instance, plcopen.coil): |
|
169 |
if len(paths) > 1: |
|
170 |
return tuple(paths) |
|
171 |
else: |
|
172 |
return paths |
|
173 |
else: |
|
174 |
if len(paths) > 1: |
|
175 |
return [variable, tuple(paths)] |
|
176 |
elif type(paths[0]) == ListType: |
|
177 |
return [variable] + paths[0] |
|
178 |
elif paths[0]: |
|
179 |
return [variable, paths[0]] |
|
180 |
else: |
|
181 |
return variable |
|
182 |
||
2 | 183 |
def ExtractDivergenceInput(self, divergence, pou): |
184 |
connectionPointIn = divergence.getConnectionPointIn() |
|
185 |
if connectionPointIn: |
|
186 |
connections = connectionPointIn.getConnections() |
|
187 |
if len(connections) == 1: |
|
188 |
instanceLocalId = connections[0].getRefLocalId() |
|
189 |
return pou.body.getContentInstance(instanceLocalId) |
|
190 |
return None |
|
191 |
||
192 |
def ExtractConvergenceInputs(self, convergence, pou): |
|
193 |
instances = [] |
|
194 |
for connectionPointIn in convergence.getConnectionPointIn(): |
|
195 |
connections = connectionPointIn.getConnections() |
|
196 |
if len(connections) == 1: |
|
197 |
instanceLocalId = connections[0].getRefLocalId() |
|
198 |
instances.append(pou.body.getContentInstance(instanceLocalId)) |
|
199 |
return instances |
|
200 |
||
1 | 201 |
def GenerateSFCStep(self, step, pou): |
0 | 202 |
step_name = step.getName() |
1 | 203 |
if step_name not in self.SFCNetworks["Steps"].keys(): |
204 |
if step.getInitialStep(): |
|
205 |
self.InitialSteps.append(step_name) |
|
0 | 206 |
step_infos = {"initial" : step.getInitialStep(), "transitions" : [], "actions" : []} |
207 |
if step.connectionPointIn: |
|
208 |
instances = [] |
|
209 |
connections = step.connectionPointIn.getConnections() |
|
210 |
if len(connections) == 1: |
|
211 |
instanceLocalId = connections[0].getRefLocalId() |
|
212 |
instance = pou.body.getContentInstance(instanceLocalId) |
|
213 |
if isinstance(instance, plcopen.transition): |
|
214 |
instances.append(instance) |
|
215 |
elif isinstance(instance, plcopen.selectionConvergence): |
|
2 | 216 |
instances.extend(self.ExtractConvergenceInputs(instance, pou)) |
217 |
elif isinstance(instance, plcopen.simultaneousDivergence): |
|
218 |
transition = self.ExtractDivergenceInput(instance, pou) |
|
219 |
if transition: |
|
220 |
if isinstance(transition, plcopen.transition): |
|
1 | 221 |
instances.append(transition) |
2 | 222 |
elif isinstance(transition, plcopen.selectionConvergence): |
223 |
instances.extend(self.ExtractConvergenceInputs(transition, pou)) |
|
0 | 224 |
for instance in instances: |
2 | 225 |
self.GenerateSFCTransition(instance, pou) |
1 | 226 |
if instance in self.SFCNetworks["Transitions"].keys(): |
227 |
self.SFCNetworks["Transitions"][instance]["to"].append(step_name) |
|
228 |
self.SFCNetworks["Steps"][step_name] = step_infos |
|
0 | 229 |
|
230 |
def GenerateSFCJump(self, jump, pou): |
|
231 |
jump_target = jump.getTargetName() |
|
232 |
if jump.connectionPointIn: |
|
233 |
instances = [] |
|
234 |
connections = jump.connectionPointIn.getConnections() |
|
235 |
if len(connections) == 1: |
|
236 |
instanceLocalId = connections[0].getRefLocalId() |
|
237 |
instance = pou.body.getContentInstance(instanceLocalId) |
|
238 |
if isinstance(instance, plcopen.transition): |
|
239 |
instances.append(instance) |
|
240 |
elif isinstance(instance, plcopen.selectionConvergence): |
|
2 | 241 |
instances.extend(self.ExtractConvergenceInputs(instance, pou)) |
242 |
elif isinstance(instance, plcopen.simultaneousDivergence): |
|
243 |
transition = self.ExtractDivergenceInput(instance, pou) |
|
244 |
if transition: |
|
245 |
if isinstance(transition, plcopen.transition): |
|
1 | 246 |
instances.append(transition) |
2 | 247 |
elif isinstance(transition, plcopen.selectionConvergence): |
248 |
instances.extend(self.ExtractConvergenceInputs(transition, pou)) |
|
0 | 249 |
for instance in instances: |
2 | 250 |
self.GenerateSFCTransition(instance, pou) |
1 | 251 |
if instance in self.SFCNetworks["Transitions"].keys(): |
252 |
self.SFCNetworks["Transitions"][instance]["to"].append(jump_target) |
|
253 |
||
254 |
def GenerateSFCStepActions(self, actionBlock, pou): |
|
0 | 255 |
connections = actionBlock.connectionPointIn.getConnections() |
256 |
if len(connections) == 1: |
|
257 |
stepLocalId = connections[0].getRefLocalId() |
|
258 |
step = pou.body.getContentInstance(stepLocalId) |
|
1 | 259 |
self.GenerateSFCStep(step, pou) |
0 | 260 |
step_name = step.getName() |
1 | 261 |
if step_name in self.SFCNetworks["Steps"].keys(): |
0 | 262 |
actions = actionBlock.getActions() |
263 |
for action in actions: |
|
1 | 264 |
action_infos = {"qualifier" : action["qualifier"], "content" : action["value"]} |
265 |
if "duration" in action: |
|
266 |
action_infos["duration"] = action["duration"] |
|
267 |
if "indicator" in action: |
|
268 |
action_infos["indicator"] = action["indicator"] |
|
269 |
if action["type"] == "reference": |
|
270 |
self.GenerateSFCAction(action["value"], pou) |
|
271 |
self.SFCNetworks["Steps"][step_name]["actions"].append(action_infos) |
|
272 |
||
273 |
def GenerateSFCAction(self, action_name, pou): |
|
274 |
if action_name not in self.SFCNetworks["Actions"].keys(): |
|
275 |
actionContent = pou.getAction(action_name) |
|
276 |
if actionContent: |
|
277 |
actionType = actionContent.getBodyType() |
|
278 |
actionBody = actionContent.getBody() |
|
279 |
if actionType in ["ST", "IL"]: |
|
280 |
self.SFCNetworks["Actions"][action_name] = ReIndentText(actionContent.getText(), 4) |
|
281 |
elif actionType == "FBD": |
|
282 |
for instance in actionBody.getContentInstances(): |
|
283 |
if isinstance(instance, plcopen.outVariable): |
|
284 |
var = instance.getExpression() |
|
285 |
connections = instance.connectionPointIn.getConnections() |
|
286 |
if connections and len(connections) == 1: |
|
287 |
expression = self.ComputeFBDExpression(actionBody, connections[0]) |
|
288 |
self.SFCNetworks["Actions"][action_name] = self.Program + " %s := %s;\n"%(var, expression) |
|
289 |
self.Program = "" |
|
290 |
elif actionType == "LD": |
|
291 |
for instance in actionbody.getContentInstances(): |
|
292 |
if isinstance(instance, plcopen.coil): |
|
293 |
paths = self.GenerateLDPaths(instance, actionBody) |
|
294 |
variable = self.ExtractModifier(instance, instance.getVariable()) |
|
295 |
expression = self.ComputeLDExpression(paths, True) |
|
296 |
self.SFCNetworks["Actions"][action_name] = self.Program + " %s := %s;\n"%(variable, expression) |
|
297 |
self.Program = "" |
|
298 |
||
299 |
def GenerateSFCTransition(self, transition, pou): |
|
300 |
if transition not in self.SFCNetworks["Transitions"].keys(): |
|
301 |
steps = [] |
|
0 | 302 |
connections = transition.connectionPointIn.getConnections() |
303 |
if len(connections) == 1: |
|
304 |
instanceLocalId = connections[0].getRefLocalId() |
|
305 |
instance = pou.body.getContentInstance(instanceLocalId) |
|
306 |
if isinstance(instance, plcopen.step): |
|
2 | 307 |
steps.append(instance) |
0 | 308 |
elif isinstance(instance, plcopen.selectionDivergence): |
2 | 309 |
step = self.ExtractDivergenceInput(instance, pou) |
310 |
if step: |
|
311 |
if isinstance(step, plcopen.step): |
|
312 |
steps.append(step) |
|
313 |
elif isinstance(step, plcopen.simultaneousConvergence): |
|
314 |
steps.extend(self.ExtractConvergenceInputs(step, pou)) |
|
315 |
elif isinstance(instance, plcopen.simultaneousConvergence): |
|
316 |
steps.extend(self.ExtractConvergenceInputs(instance, pou)) |
|
1 | 317 |
transition_infos = {"from": [], "to" : []} |
318 |
transitionValues = transition.getConditionContent() |
|
319 |
if transitionValues["type"] == "inline": |
|
320 |
transition_infos["content"] = "\n := %s;\n"%transitionValues["value"] |
|
321 |
else: |
|
322 |
transitionContent = pou.getTransition(transitionValues["value"]) |
|
323 |
transitionType = transitionContent.getBodyType() |
|
324 |
transitionBody = transitionContent.getBody() |
|
325 |
if transitionType == "IL": |
|
2 | 326 |
transition_infos["content"] = ":\n%s"%ReIndentText(transitionBody.getText(), 4) |
1 | 327 |
elif transitionType == "ST": |
2 | 328 |
transition_infos["content"] = "\n%s"%ReIndentText(transitionBody.getText(), 4) |
1 | 329 |
elif conditionType == "FBD": |
330 |
for instance in transitionBody.getContentInstances(): |
|
331 |
if isinstance(instance, plcopen.outVariable): |
|
332 |
connections = instance.connectionPointIn.getConnections() |
|
333 |
if connections and len(connections) == 1: |
|
334 |
expression = self.ComputeFBDExpression(actionBody, connections[0]) |
|
335 |
transition_infos["content"] = "\n := %s;\n"%(var, expression) |
|
336 |
elif actionType == "LD": |
|
337 |
for instance in transitionbody.getContentInstances(): |
|
338 |
if isinstance(instance, plcopen.coil): |
|
339 |
paths = self.GenerateLDPaths(instance, conditionBody) |
|
340 |
expression = self.ComputeLDExpression(paths, True) |
|
341 |
transition_infos["content"] = "\n := %s;\n"%expression |
|
2 | 342 |
for step in steps: |
343 |
self.GenerateSFCStep(step, pou) |
|
344 |
step_name = step.getName() |
|
1 | 345 |
if step_name in self.SFCNetworks["Steps"].keys(): |
346 |
transition_infos["from"].append(step_name) |
|
347 |
self.SFCNetworks["Steps"][step_name]["transitions"].append(transition) |
|
348 |
self.SFCNetworks["Transitions"][transition] = transition_infos |
|
349 |
||
350 |
def ComputeSFCStep(self, step_name): |
|
351 |
if step_name in self.SFCNetworks["Steps"].keys(): |
|
352 |
step_infos = self.SFCNetworks["Steps"].pop(step_name) |
|
353 |
if step_infos["initial"]: |
|
354 |
self.Program += " INITIAL_STEP %s:\n"%step_name |
|
355 |
else: |
|
356 |
self.Program += " STEP %s:\n"%step_name |
|
357 |
actions = [] |
|
358 |
for action_infos in step_infos["actions"]: |
|
359 |
actions.append(action_infos["content"]) |
|
360 |
self.Program += " %(content)s(%(qualifier)s"%action_infos |
|
361 |
if "duration" in action_infos: |
|
362 |
self.Program += ", %(duration)s"%action_infos |
|
363 |
if "indicator" in action_infos: |
|
364 |
self.Program += ", %(indicator)s"%action_infos |
|
365 |
self.Program += ");\n" |
|
366 |
self.Program += " END_STEP\n\n" |
|
367 |
for action in actions: |
|
368 |
self.ComputeSFCAction(action) |
|
369 |
for transition in step_infos["transitions"]: |
|
370 |
self.ComputeSFCTransition(transition) |
|
371 |
||
372 |
def ComputeSFCAction(self, action_name): |
|
373 |
if action_name in self.SFCNetworks["Actions"].keys(): |
|
374 |
action_content = self.SFCNetworks["Actions"].pop(action_name) |
|
375 |
self.Program += " ACTION %s:\n%s END_ACTION\n\n"%(action_name, action_content) |
|
376 |
||
377 |
def ComputeSFCTransition(self, transition): |
|
378 |
if transition in self.SFCNetworks["Transitions"].keys(): |
|
379 |
transition_infos = self.SFCNetworks["Transitions"].pop(transition) |
|
380 |
self.Program += " TRANSITION FROM " |
|
381 |
if len(transition_infos["from"]) > 1: |
|
382 |
self.Program += "(%s)"%", ".join(transition_infos["from"]) |
|
383 |
else: |
|
384 |
self.Program += "%s"%transition_infos["from"][0] |
|
385 |
self.Program += " TO " |
|
386 |
if len(transition_infos["to"]) > 1: |
|
387 |
self.Program += "(%s)"%", ".join(transition_infos["to"]) |
|
388 |
else: |
|
389 |
self.Program += "%s"%transition_infos["to"][0] |
|
390 |
self.Program += transition_infos["content"] |
|
391 |
self.Program += " END_TRANSITION\n\n" |
|
392 |
for step_name in transition_infos["to"]: |
|
393 |
self.ComputeSFCStep(step_name) |
|
394 |
||
0 | 395 |
def ComputeLDExpression(self, paths, first = False): |
396 |
if type(paths) == TupleType: |
|
397 |
if None in paths: |
|
398 |
return "TRUE" |
|
399 |
else: |
|
400 |
var = [self.ComputeLDExpression(path) for path in paths] |
|
401 |
if first: |
|
402 |
return " OR ".join(var) |
|
403 |
else: |
|
404 |
return "(%s)"%" OR ".join(var) |
|
405 |
elif type(paths) == ListType: |
|
406 |
var = [self.ComputeLDExpression(path) for path in paths] |
|
407 |
return " AND ".join(var) |
|
408 |
else: |
|
409 |
return paths |
|
410 |
||
411 |
def ExtractModifier(self, variable, text): |
|
412 |
if variable.getNegated(): |
|
413 |
return "NOT(%s)"%text |
|
414 |
else: |
|
415 |
edge = variable.getEdge() |
|
416 |
if edge: |
|
417 |
if edge.getValue() == "rising": |
|
418 |
return self.AddTrigger("R_TRIG", text) |
|
419 |
elif edge.getValue() == "falling": |
|
420 |
return self.AddTrigger("F_TRIG", text) |
|
421 |
return text |
|
422 |
||
423 |
def AddTrigger(self, edge, text): |
|
1 | 424 |
if self.Interface[-1][0] != "VAR" or self.Interface[-1][1] or self.Interface[-1][2]: |
425 |
self.Interface.append(("VAR", False, False, [])) |
|
0 | 426 |
i = 1 |
427 |
name = "%s%d"%(edge, i) |
|
1 | 428 |
while self.IsAlreadyDefined(name): |
0 | 429 |
i += 1 |
430 |
name = "%s%d"%(edge, i) |
|
1 | 431 |
self.Interface[-1][3].append((edge, name)) |
0 | 432 |
self.Program += " %s(CLK := %s);\n"%(name, text) |
433 |
return "%s.Q"%name |
|
434 |
||
435 |
def GenerateSTProgram(self): |
|
436 |
program = "" |
|
1 | 437 |
if self.ReturnType: |
438 |
program += "%s %s : %s\n"%(self.Type, self.Name, self.ReturnType) |
|
0 | 439 |
else: |
440 |
program += "%s %s\n"%(self.Type, self.Name) |
|
1 | 441 |
for list_type, retain, constant, variables in self.Interface: |
442 |
program += " %s"%list_type |
|
443 |
if retain: |
|
444 |
program += " RETAIN" |
|
445 |
if constant: |
|
446 |
program += " CONSTANT" |
|
447 |
program += "\n" |
|
448 |
for var_type, var_name in variables: |
|
449 |
program += " %s : %s;\n"%(var_name, var_type) |
|
4
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
2
diff
changeset
|
450 |
program += " END_VAR\n" |
0 | 451 |
program += "\n" |
452 |
program += self.Program |
|
453 |
program += "END_%s\n\n"%self.Type |
|
454 |
return program |
|
455 |
||
456 |
def GenerateCurrentProgram(project): |
|
457 |
program = "" |
|
458 |
for pou in project.getPous(): |
|
459 |
pou_type = pou.getPouType().getValue() |
|
6 | 460 |
if pou_type in pouTypeNames: |
461 |
pou_program = PouProgram(pou.getName(), pouTypeNames[pou_type]) |
|
0 | 462 |
else: |
463 |
raise ValueError, "Undefined pou type" |
|
464 |
pou_program.GenerateInterface(pou.getInterface()) |
|
465 |
pou_program.GenerateProgram(pou) |
|
466 |
program += pou_program.GenerateSTProgram() |
|
467 |
return program |
|
468 |