26 from __future__ import absolute_import |
26 from __future__ import absolute_import |
27 from types import * |
27 from types import * |
28 import re |
28 import re |
29 from plcopen import PLCOpenParser |
29 from plcopen import PLCOpenParser |
30 from plcopen.structures import * |
30 from plcopen.structures import * |
|
31 from plcopen.types_enums import * |
31 |
32 |
32 |
33 |
33 # Dictionary associating PLCOpen variable categories to the corresponding |
34 # Dictionary associating PLCOpen variable categories to the corresponding |
34 # IEC 61131-3 variable categories |
35 # IEC 61131-3 variable categories |
35 varTypeNames = {"localVars": "VAR", "tempVars": "VAR_TEMP", "inputVars": "VAR_INPUT", |
36 varTypeNames = {"localVars": "VAR", "tempVars": "VAR_TEMP", "inputVars": "VAR_INPUT", |
132 # If not mark data type as computed |
133 # If not mark data type as computed |
133 self.DatatypeComputed[datatype_name] = True |
134 self.DatatypeComputed[datatype_name] = True |
134 |
135 |
135 # Getting datatype model from project |
136 # Getting datatype model from project |
136 datatype = self.Project.getdataType(datatype_name) |
137 datatype = self.Project.getdataType(datatype_name) |
137 tagname = self.Controler.ComputeDataTypeName(datatype.getname()) |
138 tagname = ComputeDataTypeName(datatype.getname()) |
138 datatype_def = [(" ", ()), |
139 datatype_def = [(" ", ()), |
139 (datatype.getname(), (tagname, "name")), |
140 (datatype.getname(), (tagname, "name")), |
140 (" : ", ())] |
141 (" : ", ())] |
141 basetype_content = datatype.baseType.getcontent() |
142 basetype_content = datatype.baseType.getcontent() |
142 basetype_content_type = basetype_content.getLocalTag() |
143 basetype_content_type = basetype_content.getLocalTag() |
266 if model.search(text) is not None: |
267 if model.search(text) is not None: |
267 self.GeneratePouProgram(pou_name) |
268 self.GeneratePouProgram(pou_name) |
268 |
269 |
269 # Generate a configuration from its model |
270 # Generate a configuration from its model |
270 def GenerateConfiguration(self, configuration): |
271 def GenerateConfiguration(self, configuration): |
271 tagname = self.Controler.ComputeConfigurationName(configuration.getname()) |
272 tagname = ComputeConfigurationName(configuration.getname()) |
272 config = [("\nCONFIGURATION ", ()), |
273 config = [("\nCONFIGURATION ", ()), |
273 (configuration.getname(), (tagname, "name")), |
274 (configuration.getname(), (tagname, "name")), |
274 ("\n", ())] |
275 ("\n", ())] |
275 var_number = 0 |
276 var_number = 0 |
276 |
277 |
340 config += [("END_CONFIGURATION\n", ())] |
341 config += [("END_CONFIGURATION\n", ())] |
341 return config |
342 return config |
342 |
343 |
343 # Generate a resource from its model |
344 # Generate a resource from its model |
344 def GenerateResource(self, resource, config_name): |
345 def GenerateResource(self, resource, config_name): |
345 tagname = self.Controler.ComputeConfigurationResourceName(config_name, resource.getname()) |
346 tagname = ComputeConfigurationResourceName(config_name, resource.getname()) |
346 resrce = [("\n RESOURCE ", ()), |
347 resrce = [("\n RESOURCE ", ()), |
347 (resource.getname(), (tagname, "name")), |
348 (resource.getname(), (tagname, "name")), |
348 (" ON PLC\n", ())] |
349 (" ON PLC\n", ())] |
349 var_number = 0 |
350 var_number = 0 |
350 # Generate any global variable in configuration |
351 # Generate any global variable in configuration |
516 def __init__(self, parent, name, type, errors, warnings): |
517 def __init__(self, parent, name, type, errors, warnings): |
517 # Keep Reference to the parent generator |
518 # Keep Reference to the parent generator |
518 self.ParentGenerator = parent |
519 self.ParentGenerator = parent |
519 self.Name = name |
520 self.Name = name |
520 self.Type = type |
521 self.Type = type |
521 self.TagName = self.ParentGenerator.Controler.ComputePouName(name) |
522 self.TagName = ComputePouName(name) |
522 self.CurrentIndent = " " |
523 self.CurrentIndent = " " |
523 self.ReturnType = None |
524 self.ReturnType = None |
524 self.Interface = [] |
525 self.Interface = [] |
525 self.InitialSteps = [] |
526 self.InitialSteps = [] |
526 self.ComputedBlocks = {} |
527 self.ComputedBlocks = {} |
576 for var_name, var_type, _var_modifier in blocktype["inputs"] + blocktype["outputs"]: |
577 for var_name, var_type, _var_modifier in blocktype["inputs"] + blocktype["outputs"]: |
577 if var_name == name: |
578 if var_name == name: |
578 current_type = var_type |
579 current_type = var_type |
579 break |
580 break |
580 else: |
581 else: |
581 tagname = self.ParentGenerator.Controler.ComputeDataTypeName(current_type) |
582 tagname = ComputeDataTypeName(current_type) |
582 infos = self.ParentGenerator.Controler.GetDataTypeInfos(tagname) |
583 infos = self.ParentGenerator.Controler.GetDataTypeInfos(tagname) |
583 if infos is not None and infos["type"] == "Structure": |
584 if infos is not None and infos["type"] == "Structure": |
584 name = parts.pop(0) |
585 name = parts.pop(0) |
585 current_type = None |
586 current_type = None |
586 for element in infos["elements"]: |
587 for element in infos["elements"]: |
839 raise PLCGenException( |
840 raise PLCGenException( |
840 _("No informations found for \"%s\" block") % (instance.gettypeName())) |
841 _("No informations found for \"%s\" block") % (instance.gettypeName())) |
841 if body_type == "SFC": |
842 if body_type == "SFC": |
842 previous_tagname = self.TagName |
843 previous_tagname = self.TagName |
843 for action in pou.getactionList(): |
844 for action in pou.getactionList(): |
844 self.TagName = self.ParentGenerator.Controler.ComputePouActionName(self.Name, action.getname()) |
845 self.TagName = ComputePouActionName(self.Name, action.getname()) |
845 self.ComputeConnectionTypes(action) |
846 self.ComputeConnectionTypes(action) |
846 for transition in pou.gettransitionList(): |
847 for transition in pou.gettransitionList(): |
847 self.TagName = self.ParentGenerator.Controler.ComputePouTransitionName(self.Name, transition.getname()) |
848 self.TagName = ComputePouTransitionName(self.Name, transition.getname()) |
848 self.ComputeConnectionTypes(transition) |
849 self.ComputeConnectionTypes(transition) |
849 self.TagName = previous_tagname |
850 self.TagName = previous_tagname |
850 |
851 |
851 def ComputeBlockInputTypes(self, instance, block_infos, body): |
852 def ComputeBlockInputTypes(self, instance, block_infos, body): |
852 undefined = {} |
853 undefined = {} |
1495 def GenerateSFCAction(self, action_name, pou): |
1496 def GenerateSFCAction(self, action_name, pou): |
1496 if action_name not in self.SFCNetworks["Actions"].keys(): |
1497 if action_name not in self.SFCNetworks["Actions"].keys(): |
1497 actionContent = pou.getaction(action_name) |
1498 actionContent = pou.getaction(action_name) |
1498 if actionContent is not None: |
1499 if actionContent is not None: |
1499 previous_tagname = self.TagName |
1500 previous_tagname = self.TagName |
1500 self.TagName = self.ParentGenerator.Controler.ComputePouActionName(self.Name, action_name) |
1501 self.TagName = ComputePouActionName(self.Name, action_name) |
1501 self.ComputeProgram(actionContent) |
1502 self.ComputeProgram(actionContent) |
1502 self.SFCNetworks["Actions"][action_name] = (self.Program, (self.TagName, "name")) |
1503 self.SFCNetworks["Actions"][action_name] = (self.Program, (self.TagName, "name")) |
1503 self.Program = [] |
1504 self.Program = [] |
1504 self.TagName = previous_tagname |
1505 self.TagName = previous_tagname |
1505 |
1506 |
1538 elif transitionValues["type"] == "reference": |
1539 elif transitionValues["type"] == "reference": |
1539 transitionContent = pou.gettransition(transitionValues["value"]) |
1540 transitionContent = pou.gettransition(transitionValues["value"]) |
1540 transitionType = transitionContent.getbodyType() |
1541 transitionType = transitionContent.getbodyType() |
1541 transitionBody = transitionContent.getbody() |
1542 transitionBody = transitionContent.getbody() |
1542 previous_tagname = self.TagName |
1543 previous_tagname = self.TagName |
1543 self.TagName = self.ParentGenerator.Controler.ComputePouTransitionName(self.Name, transitionValues["value"]) |
1544 self.TagName = ComputePouTransitionName(self.Name, transitionValues["value"]) |
1544 if transitionType == "IL": |
1545 if transitionType == "IL": |
1545 transition_infos["content"] = [(":\n", ()), |
1546 transition_infos["content"] = [(":\n", ()), |
1546 (ReIndentText(transitionBody.getcontent().getanyText(), len(self.CurrentIndent)), (self.TagName, "body", len(self.CurrentIndent)))] |
1547 (ReIndentText(transitionBody.getcontent().getanyText(), len(self.CurrentIndent)), (self.TagName, "body", len(self.CurrentIndent)))] |
1547 elif transitionType == "ST": |
1548 elif transitionType == "ST": |
1548 transition_infos["content"] = [("\n", ()), |
1549 transition_infos["content"] = [("\n", ()), |