396 single = task.getsingle() |
396 single = task.getsingle() |
397 # Single argument if exists |
397 # Single argument if exists |
398 if single is not None: |
398 if single is not None: |
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: |
785 connector = None |
785 connector = None |
786 var_type = "ANY" |
786 var_type = "ANY" |
787 for element in body.getcontentInstances(): |
787 for element in body.getcontentInstances(): |
788 if isinstance(element, ConnectorClass) and element.getname() == name: |
788 if isinstance(element, ConnectorClass) and element.getname() == name: |
789 if connector is not None: |
789 if connector is not None: |
790 msg = _("More than one connector found corresponding to \"{a1}\" continuation in \"{a2}\" POU").format(a1 = name, a2 = self.Name) |
790 msg = _("More than one connector found corresponding to \"{a1}\" continuation in \"{a2}\" POU").format(a1=name, a2=self.Name) |
791 raise PLCGenException, msg |
791 raise PLCGenException, msg |
792 connector = element |
792 connector = element |
793 if connector is not None: |
793 if connector is not None: |
794 undefined = [instance.connectionPointOut, connector.connectionPointIn] |
794 undefined = [instance.connectionPointOut, connector.connectionPointIn] |
795 connected = self.GetConnectedConnector(connector.connectionPointIn, body) |
795 connected = self.GetConnectedConnector(connector.connectionPointIn, body) |
805 self.RelatedConnections.append(related) |
805 self.RelatedConnections.append(related) |
806 else: |
806 else: |
807 for connection in related: |
807 for connection in related: |
808 self.ConnectionTypes[connection] = var_type |
808 self.ConnectionTypes[connection] = var_type |
809 else: |
809 else: |
810 msg = _("No connector found corresponding to \"{a1}\" continuation in \"{a2}\" POU").format(a1 = name, a2 = self.Name) |
810 msg = _("No connector found corresponding to \"{a1}\" continuation in \"{a2}\" POU").format(a1=name, a2=self.Name) |
811 raise PLCGenException, msg |
811 raise PLCGenException, msg |
812 elif isinstance(instance, BlockClass): |
812 elif isinstance(instance, BlockClass): |
813 block_infos = self.GetBlockType(instance.gettypeName(), "undefined") |
813 block_infos = self.GetBlockType(instance.gettypeName(), "undefined") |
814 if block_infos is not None: |
814 if block_infos is not None: |
815 self.ComputeBlockInputTypes(instance, block_infos, body) |
815 self.ComputeBlockInputTypes(instance, block_infos, body) |
960 self.ParentGenerator.GeneratePouProgram(block_type) |
960 self.ParentGenerator.GeneratePouProgram(block_type) |
961 block_infos = self.GetBlockType(block_type, tuple([self.ConnectionTypes.get(variable.connectionPointIn, "ANY") for variable in instance.inputVariables.getvariable() if variable.getformalParameter() != "EN"])) |
961 block_infos = self.GetBlockType(block_type, tuple([self.ConnectionTypes.get(variable.connectionPointIn, "ANY") for variable in instance.inputVariables.getvariable() if variable.getformalParameter() != "EN"])) |
962 if block_infos is None: |
962 if block_infos is None: |
963 block_infos = self.GetBlockType(block_type) |
963 block_infos = self.GetBlockType(block_type) |
964 if block_infos is None: |
964 if block_infos is None: |
965 raise PLCGenException, _("Undefined block type \"{a1}\" in \"{a2}\" POU").format(a1 = block_type, a2 = self.Name) |
965 raise PLCGenException, _("Undefined block type \"{a1}\" in \"{a2}\" POU").format(a1=block_type, a2=self.Name) |
966 try: |
966 try: |
967 self.GenerateBlock(instance, block_infos, body, None) |
967 self.GenerateBlock(instance, block_infos, body, None) |
968 except ValueError, e: |
968 except ValueError, e: |
969 raise PLCGenException, e.message |
969 raise PLCGenException, e.message |
970 elif isinstance(instance, ConnectorClass): |
970 elif isinstance(instance, ConnectorClass): |
1100 (type, (self.TagName, "block", block.getlocalId(), "type")), |
1100 (type, (self.TagName, "block", block.getlocalId(), "type")), |
1101 ("(", ())] |
1101 ("(", ())] |
1102 self.Program += JoinList([(", ", ())], vars) |
1102 self.Program += JoinList([(", ", ())], vars) |
1103 self.Program += [(");\n", ())] |
1103 self.Program += [(");\n", ())] |
1104 else: |
1104 else: |
1105 msg = _("\"{a1}\" function cancelled in \"{a2}\" POU: No input connected").format(a1 = type, a2 = self.TagName.split("::")[-1]) |
1105 msg = _("\"{a1}\" function cancelled in \"{a2}\" POU: No input connected").format(a1=type, a2=self.TagName.split("::")[-1]) |
1106 self.Warnings.append(msg) |
1106 self.Warnings.append(msg) |
1107 elif block_infos["type"] == "functionBlock": |
1107 elif block_infos["type"] == "functionBlock": |
1108 if not self.ComputedBlocks.get(block, False) and not order: |
1108 if not self.ComputedBlocks.get(block, False) and not order: |
1109 self.ComputedBlocks[block] = True |
1109 self.ComputedBlocks[block] = True |
1110 vars = [] |
1110 vars = [] |
1190 return output_name |
1190 return output_name |
1191 if link is not None: |
1191 if link is not None: |
1192 if output_parameter is None: |
1192 if output_parameter is None: |
1193 output_parameter = "" |
1193 output_parameter = "" |
1194 if name: |
1194 if name: |
1195 blockname = "{a1}({a2})".format(a1 = name, a2 = type) |
1195 blockname = "{a1}({a2})".format(a1=name, a2=type) |
1196 else: |
1196 else: |
1197 blockname = type |
1197 blockname = type |
1198 msg = _("No output {a1} variable found in block {a2} in POU {a3}. Connection must be broken").\ |
1198 msg = _("No output {a1} variable found in block {a2} in POU {a3}. Connection must be broken").\ |
1199 format(a1 = output_parameter, a2 = blockname, a3 = self.Name) |
1199 format(a1=output_parameter, a2=blockname, a3=self.Name) |
1200 raise ValueError, msg |
1200 raise ValueError, msg |
1201 |
1201 |
1202 def GeneratePaths(self, connections, body, order = False, to_inout = False): |
1202 def GeneratePaths(self, connections, body, order=False, to_inout=False): |
1203 paths = [] |
1203 paths = [] |
1204 for connection in connections: |
1204 for connection in connections: |
1205 localId = connection.getrefLocalId() |
1205 localId = connection.getrefLocalId() |
1206 next = body.getcontentInstance(localId) |
1206 next = body.getcontentInstance(localId) |
1207 if isinstance(next, LeftPowerRailClass): |
1207 if isinstance(next, LeftPowerRailClass): |
1213 self.ParentGenerator.GeneratePouProgram(block_type) |
1213 self.ParentGenerator.GeneratePouProgram(block_type) |
1214 block_infos = self.GetBlockType(block_type, tuple([self.ConnectionTypes.get(variable.connectionPointIn, "ANY") for variable in next.inputVariables.getvariable() if variable.getformalParameter() != "EN"])) |
1214 block_infos = self.GetBlockType(block_type, tuple([self.ConnectionTypes.get(variable.connectionPointIn, "ANY") for variable in next.inputVariables.getvariable() if variable.getformalParameter() != "EN"])) |
1215 if block_infos is None: |
1215 if block_infos is None: |
1216 block_infos = self.GetBlockType(block_type) |
1216 block_infos = self.GetBlockType(block_type) |
1217 if block_infos is None: |
1217 if block_infos is None: |
1218 msg = _("Undefined block type \"{a1}\" in \"{a2}\" POU").format(a1 = block_type, a2 = self.Name) |
1218 msg = _("Undefined block type \"{a1}\" in \"{a2}\" POU").format(a1=block_type, a2=self.Name) |
1219 raise PLCGenException, msg |
1219 raise PLCGenException, msg |
1220 try: |
1220 try: |
1221 paths.append(str(self.GenerateBlock(next, block_infos, body, connection, order, to_inout))) |
1221 paths.append(str(self.GenerateBlock(next, block_infos, body, connection, order, to_inout))) |
1222 except ValueError, e: |
1222 except ValueError, e: |
1223 raise PLCGenException, e.message |
1223 raise PLCGenException, e.message |
1229 else: |
1229 else: |
1230 connector = None |
1230 connector = None |
1231 for instance in body.getcontentInstances(): |
1231 for instance in body.getcontentInstances(): |
1232 if isinstance(instance, ConnectorClass) and instance.getname() == name: |
1232 if isinstance(instance, ConnectorClass) and instance.getname() == name: |
1233 if connector is not None: |
1233 if connector is not None: |
1234 msg = _("More than one connector found corresponding to \"{a1}\" continuation in \"{a2}\" POU").format(a1 = name, a2 = self.Name) |
1234 msg = _("More than one connector found corresponding to \"{a1}\" continuation in \"{a2}\" POU").format(a1=name, a2=self.Name) |
1235 raise PLCGenException, msg |
1235 raise PLCGenException, msg |
1236 connector = instance |
1236 connector = instance |
1237 if connector is not None: |
1237 if connector is not None: |
1238 connections = connector.connectionPointIn.getconnections() |
1238 connections = connector.connectionPointIn.getconnections() |
1239 if connections is not None: |
1239 if connections is not None: |
1240 expression = self.ComputeExpression(body, connections, order) |
1240 expression = self.ComputeExpression(body, connections, order) |
1241 if expression is not None: |
1241 if expression is not None: |
1242 self.ComputedConnectors[name] = expression |
1242 self.ComputedConnectors[name] = expression |
1243 paths.append(str(expression)) |
1243 paths.append(str(expression)) |
1244 else: |
1244 else: |
1245 msg = _("No connector found corresponding to \"{a1}\" continuation in \"{a2}\" POU").format(a1 = name, a2 = self.Name) |
1245 msg = _("No connector found corresponding to \"{a1}\" continuation in \"{a2}\" POU").format(a1=name, a2=self.Name) |
1246 raise PLCGenException, msg |
1246 raise PLCGenException, msg |
1247 elif isinstance(next, ContactClass): |
1247 elif isinstance(next, ContactClass): |
1248 contact_info = (self.TagName, "contact", next.getlocalId()) |
1248 contact_info = (self.TagName, "contact", next.getlocalId()) |
1249 variable = str(self.ExtractModifier(next, [(next.getvariable(), contact_info + ("reference",))], contact_info)) |
1249 variable = str(self.ExtractModifier(next, [(next.getvariable(), contact_info + ("reference",))], contact_info)) |
1250 result = self.GeneratePaths(next.connectionPointIn.getconnections(), body, order) |
1250 result = self.GeneratePaths(next.connectionPointIn.getconnections(), body, order) |
1262 paths.append(variable) |
1262 paths.append(variable) |
1263 elif isinstance(next, CoilClass): |
1263 elif isinstance(next, CoilClass): |
1264 paths.append(str(self.GeneratePaths(next.connectionPointIn.getconnections(), body, order))) |
1264 paths.append(str(self.GeneratePaths(next.connectionPointIn.getconnections(), body, order))) |
1265 return paths |
1265 return paths |
1266 |
1266 |
1267 def ComputePaths(self, paths, first = False): |
1267 def ComputePaths(self, paths, first=False): |
1268 if type(paths) == TupleType: |
1268 if type(paths) == TupleType: |
1269 if None in paths: |
1269 if None in paths: |
1270 return [("TRUE", ())] |
1270 return [("TRUE", ())] |
1271 else: |
1271 else: |
1272 vars = [self.ComputePaths(path) for path in paths] |
1272 vars = [self.ComputePaths(path) for path in paths] |
1280 elif paths is None: |
1280 elif paths is None: |
1281 return [("TRUE", ())] |
1281 return [("TRUE", ())] |
1282 else: |
1282 else: |
1283 return eval(paths) |
1283 return eval(paths) |
1284 |
1284 |
1285 def ComputeExpression(self, body, connections, order = False, to_inout = False): |
1285 def ComputeExpression(self, body, connections, order=False, to_inout=False): |
1286 paths = self.GeneratePaths(connections, body, order, to_inout) |
1286 paths = self.GeneratePaths(connections, body, order, to_inout) |
1287 if len(paths) == 0: |
1287 if len(paths) == 0: |
1288 return None |
1288 return None |
1289 if len(paths) > 1: |
1289 if len(paths) > 1: |
1290 factorized_paths = self.FactorizePaths(paths) |
1290 factorized_paths = self.FactorizePaths(paths) |
1391 |
1391 |
1392 def GenerateSFCJump(self, jump, pou): |
1392 def GenerateSFCJump(self, jump, pou): |
1393 jump_target = jump.gettargetName() |
1393 jump_target = jump.gettargetName() |
1394 if not pou.hasstep(jump_target): |
1394 if not pou.hasstep(jump_target): |
1395 pname = pou.getname() |
1395 pname = pou.getname() |
1396 msg = _("SFC jump in pou \"{a1}\" refers to non-existent SFC step \"{a2}\"").format( a1 = pname, a2 = jump_target) |
1396 msg = _("SFC jump in pou \"{a1}\" refers to non-existent SFC step \"{a2}\"").format( a1=pname, a2=jump_target) |
1397 raise PLCGenException, msg |
1397 raise PLCGenException, msg |
1398 if jump.connectionPointIn is not None: |
1398 if jump.connectionPointIn is not None: |
1399 instances = [] |
1399 instances = [] |
1400 connections = jump.connectionPointIn.getconnections() |
1400 connections = jump.connectionPointIn.getconnections() |
1401 if connections is not None and len(connections) == 1: |
1401 if connections is not None and len(connections) == 1: |
1598 self.Program += [(")", ())] |
1598 self.Program += [(")", ())] |
1599 elif len(transition_infos["from"]) == 1: |
1599 elif len(transition_infos["from"]) == 1: |
1600 self.Program += transition_infos["from"][0] |
1600 self.Program += transition_infos["from"][0] |
1601 else: |
1601 else: |
1602 msg = _("Transition with content \"{a1}\" not connected to a previous step in \"{a2}\" POU").\ |
1602 msg = _("Transition with content \"{a1}\" not connected to a previous step in \"{a2}\" POU").\ |
1603 format(a1 = transition_infos["content"], a2 = self.Name) |
1603 format(a1=transition_infos["content"], a2=self.Name) |
1604 raise PLCGenException, msg |
1604 raise PLCGenException, msg |
1605 self.Program += [(" TO ", ())] |
1605 self.Program += [(" TO ", ())] |
1606 if len(transition_infos["to"]) > 1: |
1606 if len(transition_infos["to"]) > 1: |
1607 self.Program += [("(", ())] |
1607 self.Program += [("(", ())] |
1608 self.Program += JoinList([(", ", ())], transition_infos["to"]) |
1608 self.Program += JoinList([(", ", ())], transition_infos["to"]) |
1609 self.Program += [(")", ())] |
1609 self.Program += [(")", ())] |
1610 elif len(transition_infos["to"]) == 1: |
1610 elif len(transition_infos["to"]) == 1: |
1611 self.Program += transition_infos["to"][0] |
1611 self.Program += transition_infos["to"][0] |
1612 else: |
1612 else: |
1613 msg = _("Transition with content \"{a1}\" not connected to a next step in \"{a2}\" POU").\ |
1613 msg = _("Transition with content \"{a1}\" not connected to a next step in \"{a2}\" POU").\ |
1614 format(a1 = transition_infos["content"], a2 = self.Name) |
1614 format(a1=transition_infos["content"], a2=self.Name) |
1615 raise PLCGenException, msg |
1615 raise PLCGenException, msg |
1616 self.Program += transition_infos["content"] |
1616 self.Program += transition_infos["content"] |
1617 self.Program += [("%sEND_TRANSITION\n\n" % self.CurrentIndent, ())] |
1617 self.Program += [("%sEND_TRANSITION\n\n" % self.CurrentIndent, ())] |
1618 for [(step_name, step_infos)] in transition_infos["to"]: |
1618 for [(step_name, step_infos)] in transition_infos["to"]: |
1619 self.ComputeSFCStep(step_name) |
1619 self.ComputeSFCStep(step_name) |