27 from types import * |
27 from types import * |
28 import re |
28 import re |
29 |
29 |
30 # Dictionary associating PLCOpen variable categories to the corresponding |
30 # Dictionary associating PLCOpen variable categories to the corresponding |
31 # IEC 61131-3 variable categories |
31 # IEC 61131-3 variable categories |
32 varTypeNames = {"localVars" : "VAR", "tempVars" : "VAR_TEMP", "inputVars" : "VAR_INPUT", |
32 varTypeNames = {"localVars": "VAR", "tempVars": "VAR_TEMP", "inputVars": "VAR_INPUT", |
33 "outputVars" : "VAR_OUTPUT", "inOutVars" : "VAR_IN_OUT", "externalVars" : "VAR_EXTERNAL", |
33 "outputVars": "VAR_OUTPUT", "inOutVars": "VAR_IN_OUT", "externalVars": "VAR_EXTERNAL", |
34 "globalVars" : "VAR_GLOBAL", "accessVars" : "VAR_ACCESS"} |
34 "globalVars": "VAR_GLOBAL", "accessVars": "VAR_ACCESS"} |
35 |
35 |
36 |
36 |
37 # Dictionary associating PLCOpen POU categories to the corresponding |
37 # Dictionary associating PLCOpen POU categories to the corresponding |
38 # IEC 61131-3 POU categories |
38 # IEC 61131-3 POU categories |
39 pouTypeNames = {"function" : "FUNCTION", "functionBlock" : "FUNCTION_BLOCK", "program" : "PROGRAM"} |
39 pouTypeNames = {"function": "FUNCTION", "functionBlock": "FUNCTION_BLOCK", "program": "PROGRAM"} |
40 |
40 |
41 |
41 |
42 errorVarTypes = { |
42 errorVarTypes = { |
43 "VAR_INPUT": "var_input", |
43 "VAR_INPUT": "var_input", |
44 "VAR_OUTPUT": "var_output", |
44 "VAR_OUTPUT": "var_output", |
78 return cmp(ay, by) |
78 return cmp(ay, by) |
79 |
79 |
80 |
80 |
81 def JoinList(separator, mylist): |
81 def JoinList(separator, mylist): |
82 """ Helper for emulate join on element list """ |
82 """ Helper for emulate join on element list """ |
83 if len(mylist) > 0 : |
83 if len(mylist) > 0: |
84 return reduce(lambda x, y: x + separator + y, mylist) |
84 return reduce(lambda x, y: x + separator + y, mylist) |
85 else : |
85 else: |
86 return mylist |
86 return mylist |
87 |
87 |
88 #------------------------------------------------------------------------------- |
88 #------------------------------------------------------------------------------- |
89 # Specific exception for PLC generating errors |
89 # Specific exception for PLC generating errors |
90 #------------------------------------------------------------------------------- |
90 #------------------------------------------------------------------------------- |
185 ("..", ()), |
185 ("..", ()), |
186 ("%s" % dimension.getupper(), (tagname, "range", i, "upper"))] |
186 ("%s" % dimension.getupper(), (tagname, "range", i, "upper"))] |
187 for i, dimension in enumerate(basetype_content.getdimension())] |
187 for i, dimension in enumerate(basetype_content.getdimension())] |
188 datatype_def += [("ARRAY [", ())] |
188 datatype_def += [("ARRAY [", ())] |
189 datatype_def += JoinList([(",", ())], dimensions) |
189 datatype_def += JoinList([(",", ())], dimensions) |
190 datatype_def += [("] OF " , ()), |
190 datatype_def += [("] OF ", ()), |
191 (basetype_name, (tagname, "base"))] |
191 (basetype_name, (tagname, "base"))] |
192 # Data type is a structure |
192 # Data type is a structure |
193 elif basetype_content_type == "struct": |
193 elif basetype_content_type == "struct": |
194 elements = [] |
194 elements = [] |
195 for i, element in enumerate(basetype_content.getvariable()): |
195 for i, element in enumerate(basetype_content.getvariable()): |
399 if len(single) == 0: |
399 if len(single) == 0: |
400 msg = _("Source signal has to be defined for single task '{a1}' in resource '{a2}.{a3}'.").\ |
400 msg = _("Source signal has to be defined for single task '{a1}' in resource '{a2}.{a3}'.").\ |
401 format(a1 = task.getname(), a2 = config_name, a3 = resource.getname()) |
401 format(a1 = task.getname(), a2 = config_name, a3 = resource.getname()) |
402 raise PLCGenException, msg |
402 raise PLCGenException, msg |
403 |
403 |
404 if single[0]=='[' and single[-1]==']' : |
404 if single[0]=='[' and single[-1]==']': |
405 SNGLKW = "MULTI" |
405 SNGLKW = "MULTI" |
406 else: |
406 else: |
407 SNGLKW = "SINGLE" |
407 SNGLKW = "SINGLE" |
408 resrce += [(SNGLKW + " := ", ()), |
408 resrce += [(SNGLKW + " := ", ()), |
409 (single, (tagname, "task", task_number, "single")), |
409 (single, (tagname, "task", task_number, "single")), |
914 self.GenerateSFCTransition(instance, pou) |
914 self.GenerateSFCTransition(instance, pou) |
915 elif isinstance(instance, JumpStepClass): |
915 elif isinstance(instance, JumpStepClass): |
916 self.GenerateSFCJump(instance, pou) |
916 self.GenerateSFCJump(instance, pou) |
917 if len(self.InitialSteps) > 0 and len(self.SFCComputedBlocks) > 0: |
917 if len(self.InitialSteps) > 0 and len(self.SFCComputedBlocks) > 0: |
918 action_name = "COMPUTE_FUNCTION_BLOCKS" |
918 action_name = "COMPUTE_FUNCTION_BLOCKS" |
919 action_infos = {"qualifier" : "S", "content" : action_name} |
919 action_infos = {"qualifier": "S", "content": action_name} |
920 self.SFCNetworks["Steps"][self.InitialSteps[0]]["actions"].append(action_infos) |
920 self.SFCNetworks["Steps"][self.InitialSteps[0]]["actions"].append(action_infos) |
921 self.SFCNetworks["Actions"][action_name] = (self.SFCComputedBlocks, ()) |
921 self.SFCNetworks["Actions"][action_name] = (self.SFCComputedBlocks, ()) |
922 self.Program = [] |
922 self.Program = [] |
923 self.IndentLeft() |
923 self.IndentLeft() |
924 for initialstep in self.InitialSteps: |
924 for initialstep in self.InitialSteps: |
925 self.ComputeSFCStep(initialstep) |
925 self.ComputeSFCStep(initialstep) |
926 else: |
926 else: |
927 otherInstances = {"outVariables&coils" : [], "blocks" : [], "connectors" : []} |
927 otherInstances = {"outVariables&coils": [], "blocks": [], "connectors": []} |
928 orderedInstances = [] |
928 orderedInstances = [] |
929 for instance in body.getcontentInstances(): |
929 for instance in body.getcontentInstances(): |
930 if isinstance(instance, (OutVariableClass, InOutVariableClass, BlockClass)): |
930 if isinstance(instance, (OutVariableClass, InOutVariableClass, BlockClass)): |
931 executionOrderId = instance.getexecutionOrderId() |
931 executionOrderId = instance.getexecutionOrderId() |
932 if executionOrderId > 0: |
932 if executionOrderId > 0: |
1356 def GenerateSFCStep(self, step, pou): |
1356 def GenerateSFCStep(self, step, pou): |
1357 step_name = step.getname() |
1357 step_name = step.getname() |
1358 if step_name not in self.SFCNetworks["Steps"].keys(): |
1358 if step_name not in self.SFCNetworks["Steps"].keys(): |
1359 if step.getinitialStep(): |
1359 if step.getinitialStep(): |
1360 self.InitialSteps.append(step_name) |
1360 self.InitialSteps.append(step_name) |
1361 step_infos = {"id" : step.getlocalId(), |
1361 step_infos = {"id": step.getlocalId(), |
1362 "initial" : step.getinitialStep(), |
1362 "initial": step.getinitialStep(), |
1363 "transitions" : [], |
1363 "transitions": [], |
1364 "actions" : []} |
1364 "actions": []} |
1365 self.SFCNetworks["Steps"][step_name] = step_infos |
1365 self.SFCNetworks["Steps"][step_name] = step_infos |
1366 if step.connectionPointIn is not None: |
1366 if step.connectionPointIn is not None: |
1367 instances = [] |
1367 instances = [] |
1368 connections = step.connectionPointIn.getconnections() |
1368 connections = step.connectionPointIn.getconnections() |
1369 if connections is not None and len(connections) == 1: |
1369 if connections is not None and len(connections) == 1: |
1432 self.GenerateSFCStep(step, pou) |
1432 self.GenerateSFCStep(step, pou) |
1433 step_name = step.getname() |
1433 step_name = step.getname() |
1434 if step_name in self.SFCNetworks["Steps"].keys(): |
1434 if step_name in self.SFCNetworks["Steps"].keys(): |
1435 actions = actionBlock.getactions() |
1435 actions = actionBlock.getactions() |
1436 for i, action in enumerate(actions): |
1436 for i, action in enumerate(actions): |
1437 action_infos = {"id" : actionBlock.getlocalId(), |
1437 action_infos = {"id": actionBlock.getlocalId(), |
1438 "qualifier" : action["qualifier"], |
1438 "qualifier": action["qualifier"], |
1439 "content" : action["value"], |
1439 "content": action["value"], |
1440 "num" : i} |
1440 "num": i} |
1441 if "duration" in action: |
1441 if "duration" in action: |
1442 action_infos["duration"] = action["duration"] |
1442 action_infos["duration"] = action["duration"] |
1443 if "indicator" in action: |
1443 if "indicator" in action: |
1444 action_infos["indicator"] = action["indicator"] |
1444 action_infos["indicator"] = action["indicator"] |
1445 if action["type"] == "reference": |
1445 if action["type"] == "reference": |
1482 steps.append(step) |
1482 steps.append(step) |
1483 elif isinstance(step, SimultaneousConvergenceClass): |
1483 elif isinstance(step, SimultaneousConvergenceClass): |
1484 steps.extend(self.ExtractConvergenceInputs(step, pou)) |
1484 steps.extend(self.ExtractConvergenceInputs(step, pou)) |
1485 elif isinstance(instance, SimultaneousConvergenceClass): |
1485 elif isinstance(instance, SimultaneousConvergenceClass): |
1486 steps.extend(self.ExtractConvergenceInputs(instance, pou)) |
1486 steps.extend(self.ExtractConvergenceInputs(instance, pou)) |
1487 transition_infos = {"id" : transition.getlocalId(), |
1487 transition_infos = {"id": transition.getlocalId(), |
1488 "priority": transition.getpriority(), |
1488 "priority": transition.getpriority(), |
1489 "from": [], |
1489 "from": [], |
1490 "to" : [], |
1490 "to": [], |
1491 "content": []} |
1491 "content": []} |
1492 self.SFCNetworks["Transitions"][transition] = transition_infos |
1492 self.SFCNetworks["Transitions"][transition] = transition_infos |
1493 transitionValues = transition.getconditionContent() |
1493 transitionValues = transition.getconditionContent() |
1494 if transitionValues["type"] == "inline": |
1494 if transitionValues["type"] == "inline": |
1495 transition_infos["content"] = [("\n%s:= " % self.CurrentIndent, ()), |
1495 transition_infos["content"] = [("\n%s:= " % self.CurrentIndent, ()), |
1496 (transitionValues["value"], (self.TagName, "transition", transition.getlocalId(), "inline")), |
1496 (transitionValues["value"], (self.TagName, "transition", transition.getlocalId(), "inline")), |
1629 program += [(" : ", ()), |
1629 program += [(" : ", ()), |
1630 (self.ReturnType, (self.TagName, "return"))] |
1630 (self.ReturnType, (self.TagName, "return"))] |
1631 program += [("\n", ())] |
1631 program += [("\n", ())] |
1632 if len(self.Interface) == 0: |
1632 if len(self.Interface) == 0: |
1633 raise PLCGenException, _("No variable defined in \"%s\" POU") % self.Name |
1633 raise PLCGenException, _("No variable defined in \"%s\" POU") % self.Name |
1634 if len(self.Program) == 0 : |
1634 if len(self.Program) == 0: |
1635 raise PLCGenException, _("No body defined in \"%s\" POU") % self.Name |
1635 raise PLCGenException, _("No body defined in \"%s\" POU") % self.Name |
1636 var_number = 0 |
1636 var_number = 0 |
1637 for list_type, option, located, variables in self.Interface: |
1637 for list_type, option, located, variables in self.Interface: |
1638 variable_type = errorVarTypes.get(list_type, "var_local") |
1638 variable_type = errorVarTypes.get(list_type, "var_local") |
1639 program += [(" %s" % list_type, ())] |
1639 program += [(" %s" % list_type, ())] |