diff -r 7ea1f5094df3 -r 6a72016d721a PLCGenerator.py --- a/PLCGenerator.py Fri Jul 24 11:55:46 2009 +0200 +++ b/PLCGenerator.py Fri Jul 24 12:29:48 2009 +0200 @@ -143,9 +143,9 @@ max_value = basetype_content["value"].range.getupper() datatype_def += [(basetype_name, (tagname, "base")), (" (", ()), - ("%d"%min_value, (tagname, "lower")), + ("%s"%min_value, (tagname, "lower")), ("..", ()), - ("%d"%max_value, (tagname, "upper")), + ("%s"%max_value, (tagname, "upper")), (")",())] # Data type is an enumerated type elif basetype_content["name"] == "enum": @@ -167,9 +167,9 @@ # Array derived directly from an elementary type else: basetype_name = base_type["name"] - dimensions = [[("%d"%dimension.getlower(), (tagname, "range", i, "lower")), + dimensions = [[("%s"%dimension.getlower(), (tagname, "range", i, "lower")), ("..", ()), - ("%d"%dimension.getupper(), (tagname, "range", i, "upper"))] + ("%s"%dimension.getupper(), (tagname, "range", i, "upper"))] for i, dimension in enumerate(basetype_content["value"].getdimension())] datatype_def += [("ARRAY [", ())] datatype_def += JoinList([(",", ())], dimensions) @@ -356,16 +356,19 @@ # Interval argument if exists interval = task.getinterval() if interval: - resrce += [("INTERVAL := t#", ())] - if interval.hour != 0: - resrce += [("%dh"%interval.hour, (tagname, "task", task_number, "interval", "hour"))] - if interval.minute != 0: - resrce += [("%dm"%interval.minute, (tagname, "task", task_number, "interval", "minute"))] - if interval.second != 0: - resrce += [("%ds"%interval.second, (tagname, "task", task_number, "interval", "second"))] - if interval.microsecond != 0: - resrce += [("%dms"%(interval.microsecond / 1000), (tagname, "task", task_number, "interval", "millisecond"))] - resrce += [(",", ())] + resrce += [("INTERVAL := ", ()), + (interval, (tagname, "task", task_number, "interval")), + (",", ())] +## resrce += [("INTERVAL := t#", ())] +## if interval.hour != 0: +## resrce += [("%dh"%interval.hour, (tagname, "task", task_number, "interval", "hour"))] +## if interval.minute != 0: +## resrce += [("%dm"%interval.minute, (tagname, "task", task_number, "interval", "minute"))] +## if interval.second != 0: +## resrce += [("%ds"%interval.second, (tagname, "task", task_number, "interval", "second"))] +## if interval.microsecond != 0: +## resrce += [("%dms"%(interval.microsecond / 1000), (tagname, "task", task_number, "interval", "millisecond"))] +## resrce += [(",", ())] # Priority argument resrce += [("PRIORITY := ", ()), ("%d"%task.getpriority(), (tagname, "task", task_number, "priority")), @@ -380,7 +383,7 @@ (" WITH ", ()), (task.getname(), (tagname, "instance", instance_number, "task")), (" : ", ()), - (instance.gettype(), (tagname, "instance", instance_number, "type")), + (instance.gettypeName(), (tagname, "instance", instance_number, "type")), (";\n", ())] instance_number += 1 # Generate any program assign to no task @@ -388,7 +391,7 @@ resrce += [(" PROGRAM ", ()), (instance.getname(), (tagname, "instance", instance_number, "name")), (" : ", ()), - (instance.gettype(), (tagname, "instance", instance_number, "type")), + (instance.gettypeName(), (tagname, "instance", instance_number, "type")), (";\n", ())] instance_number += 1 resrce += [(" END_RESOURCE\n", ())] @@ -532,6 +535,8 @@ interface = pou.getinterface() if interface is not None: body = pou.getbody() + if isinstance(body, ListType): + body = body[0] body_content = body.getcontent() if self.Type == "FUNCTION": returntype_content = interface.getreturnType().getcontent() @@ -596,6 +601,8 @@ def ComputeConnectionTypes(self, pou): body = pou.getbody() + if isinstance(body, ListType): + body = body[0] body_content = body.getcontent() body_type = body_content["name"] if body_type in ["FBD", "LD", "SFC"]: @@ -684,56 +691,61 @@ raise PLCGenException, "No connector found corresponding to \"%s\" continuation in \"%s\" POU"%(name, self.Name) elif isinstance(instance, plcopen.fbdObjects_block): block_infos = self.GetBlockType(instance.gettypeName()) - undefined = {} - for variable in instance.outputVariables.getvariable(): - output_name = variable.getformalParameter() - if output_name == "ENO": - for connection in self.ExtractRelatedConnections(variable.connectionPointOut): - self.ConnectionTypes[connection] = "BOOL" - else: - for oname, otype, oqualifier in block_infos["outputs"]: - if output_name == oname: - if otype.startswith("ANY"): - if not undefined.has_key(otype): - undefined[otype] = [] - undefined[otype].append(variable.connectionPointOut) - elif not self.ConnectionTypes.has_key(variable.connectionPointOut): - for connection in self.ExtractRelatedConnections(variable.connectionPointOut): - self.ConnectionTypes[connection] = otype - for variable in instance.inputVariables.getvariable(): - input_name = variable.getformalParameter() - if input_name == "EN": - for connection in self.ExtractRelatedConnections(variable.connectionPointIn): - self.ConnectionTypes[connection] = "BOOL" - for iname, itype, iqualifier in block_infos["inputs"]: - if input_name == iname: - connected = self.GetConnectedConnector(variable.connectionPointIn, body) - if itype.startswith("ANY"): - if not undefined.has_key(itype): - undefined[itype] = [] - undefined[itype].append(variable.connectionPointIn) - if connected: - undefined[itype].append(connected) + if block_infos is not None: + undefined = {} + for variable in instance.outputVariables.getvariable(): + output_name = variable.getformalParameter() + if output_name == "ENO": + for connection in self.ExtractRelatedConnections(variable.connectionPointOut): + self.ConnectionTypes[connection] = "BOOL" + else: + for oname, otype, oqualifier in block_infos["outputs"]: + if output_name == oname: + if otype.startswith("ANY"): + if not undefined.has_key(otype): + undefined[otype] = [] + undefined[otype].append(variable.connectionPointOut) + elif not self.ConnectionTypes.has_key(variable.connectionPointOut): + for connection in self.ExtractRelatedConnections(variable.connectionPointOut): + self.ConnectionTypes[connection] = otype + for variable in instance.inputVariables.getvariable(): + input_name = variable.getformalParameter() + if input_name == "EN": + for connection in self.ExtractRelatedConnections(variable.connectionPointIn): + self.ConnectionTypes[connection] = "BOOL" + for iname, itype, iqualifier in block_infos["inputs"]: + if input_name == iname: + connected = self.GetConnectedConnector(variable.connectionPointIn, body) + if itype.startswith("ANY"): + if not undefined.has_key(itype): + undefined[itype] = [] + undefined[itype].append(variable.connectionPointIn) + if connected: + undefined[itype].append(connected) + else: + self.ConnectionTypes[variable.connectionPointIn] = itype + if connected and not self.ConnectionTypes.has_key(connected): + for connection in self.ExtractRelatedConnections(connected): + self.ConnectionTypes[connection] = itype + for var_type, connections in undefined.items(): + related = [] + for connection in connections: + if self.ConnectionTypes.has_key(connection): + var_type = self.ConnectionTypes[connection] else: - self.ConnectionTypes[variable.connectionPointIn] = itype - if connected and not self.ConnectionTypes.has_key(connected): - for connection in self.ExtractRelatedConnections(connected): - self.ConnectionTypes[connection] = itype - for var_type, connections in undefined.items(): - related = [] - for connection in connections: - if self.ConnectionTypes.has_key(connection): - var_type = self.ConnectionTypes[connection] + related.extend(self.ExtractRelatedConnections(connection)) + if var_type.startswith("ANY") and len(related) > 0: + self.RelatedConnections.append(related) else: - related.extend(self.ExtractRelatedConnections(connection)) - if var_type.startswith("ANY") and len(related) > 0: - self.RelatedConnections.append(related) - else: - for connection in related: - self.ConnectionTypes[connection] = var_type - + for connection in related: + self.ConnectionTypes[connection] = var_type + else: + raise PLCGenException, _("No informations found for \"%s\" block")%(instance.gettypeName()) + def ComputeProgram(self, pou): body = pou.getbody() + if isinstance(body, ListType): + body = body[0] body_content = body.getcontent() body_type = body_content["name"] if body_type in ["IL","ST"]: @@ -958,7 +970,10 @@ connections = connectionPointIn.getconnections() if connections is not None and len(connections) == 1: instanceLocalId = connections[0].getrefLocalId() - return pou.body.getcontentInstance(instanceLocalId) + body = pou.getbody() + if isinstance(body, ListType): + body = body[0] + return body.getcontentInstance(instanceLocalId) return None def ExtractConvergenceInputs(self, convergence, pou): @@ -967,7 +982,10 @@ connections = connectionPointIn.getconnections() if len(connections) == 1: instanceLocalId = connections[0].getrefLocalId() - instances.append(pou.body.getcontentInstance(instanceLocalId)) + body = pou.getbody() + if isinstance(body, ListType): + body = body[0] + instances.append(body.getcontentInstance(instanceLocalId)) return instances def GenerateSFCStep(self, step, pou): @@ -984,7 +1002,10 @@ connections = step.connectionPointIn.getconnections() if len(connections) == 1: instanceLocalId = connections[0].getrefLocalId() - instance = pou.body.getcontentInstance(instanceLocalId) + body = pou.getbody() + if isinstance(body, ListType): + body = body[0] + instance = body.getcontentInstance(instanceLocalId) if isinstance(instance, plcopen.sfcObjects_transition): instances.append(instance) elif isinstance(instance, plcopen.sfcObjects_selectionConvergence): @@ -1010,7 +1031,10 @@ connections = jump.connectionPointIn.getconnections() if len(connections) == 1: instanceLocalId = connections[0].getrefLocalId() - instance = pou.body.getcontentInstance(instanceLocalId) + body = pou.getbody() + if isinstance(body, ListType): + body = body[0] + instance = body.getcontentInstance(instanceLocalId) if isinstance(instance, plcopen.sfcObjects_transition): instances.append(instance) elif isinstance(instance, plcopen.sfcObjects_selectionConvergence): @@ -1032,7 +1056,10 @@ connections = actionBlock.connectionPointIn.getconnections() if connections is not None and len(connections) == 1: stepLocalId = connections[0].getrefLocalId() - step = pou.body.getcontentInstance(stepLocalId) + body = pou.getbody() + if isinstance(body, ListType): + body = body[0] + step = body.getcontentInstance(stepLocalId) self.GenerateSFCStep(step, pou) step_name = step.getname() if step_name in self.SFCNetworks["Steps"].keys(): @@ -1073,7 +1100,10 @@ connections = transition.connectionPointIn.getconnections() if connections is not None and len(connections) == 1: instanceLocalId = connections[0].getrefLocalId() - instance = pou.body.getcontentInstance(instanceLocalId) + body = pou.getbody() + if isinstance(body, ListType): + body = body[0] + instance = body.getcontentInstance(instanceLocalId) if isinstance(instance, plcopen.sfcObjects_step): steps.append(instance) elif isinstance(instance, plcopen.sfcObjects_selectionDivergence): @@ -1119,6 +1149,8 @@ self.TagName = previous_tagname elif transitionValues["type"] == "connection": body = pou.getbody() + if isinstance(body, ListType): + body = body[0] connections = transition.getconnections() if connections is not None: expression = self.ComputeExpression(body, connections)