--- a/PLCGenerator.py Tue Jan 22 10:53:34 2008 +0100
+++ b/PLCGenerator.py Tue Jan 22 10:57:41 2008 +0100
@@ -41,106 +41,110 @@
compute = ""
lines = text.splitlines()
if len(lines) > 0:
- spaces = 0
- while lines[0][spaces] == " ":
- spaces += 1
- indent = ""
- for i in xrange(spaces, nb_spaces):
- indent += " "
- for line in lines:
- if line != "":
- compute += "%s%s\n"%(indent, line)
- else:
- compute += "\n"
+ line_num = 0
+ while line_num < len(lines) and len(lines[line_num].strip()) == 0:
+ line_num += 1
+ if line_num < len(lines):
+ spaces = 0
+ while lines[line_num][spaces] == " ":
+ spaces += 1
+ indent = ""
+ for i in xrange(spaces, nb_spaces):
+ indent += " "
+ for line in lines:
+ if line != "":
+ compute += "%s%s\n"%(indent, line)
+ else:
+ compute += "\n"
return compute
def GenerateDataType(datatype_name):
if not datatypeComputed.get(datatype_name, True):
datatypeComputed[datatype_name] = True
global currentProject, currentProgram
- datatype = currentProject.getDataType(datatype_name)
- datatype_def = " %s :"%datatype.getName()
- basetype_content = datatype.baseType.getContent()
+ datatype = currentProject.getdataType(datatype_name)
+ datatype_def = " %s :"%datatype.getname()
+ basetype_content = datatype.baseType.getcontent()
if basetype_content["name"] in ["string", "wstring"]:
datatype_def += " %s"%basetype_content["name"].upper()
elif basetype_content["name"] == "derived":
- basetype_name = basetype_content["value"].getName()
+ basetype_name = basetype_content["value"].getname()
GenerateDataType(basetype_name)
datatype_def += " %s"%basetype_name
elif basetype_content["name"] in ["subrangeSigned", "subrangeUnsigned"]:
- base_type = basetype_content["value"].baseType.getContent()
+ base_type = basetype_content["value"].baseType.getcontent()
if base_type["name"] == "derived":
- basetype_name = base_type["value"].getName()
+ basetype_name = base_type["value"].getname()
else:
basetype_name = base_type["name"]
GenerateDataType(basetype_name)
- min_value = basetype_content["value"].range.getLower()
- max_value = basetype_content["value"].range.getUpper()
+ min_value = basetype_content["value"].range.getlower()
+ max_value = basetype_content["value"].range.getupper()
datatype_def += " %s (%d..%d)"%(basetype_name, min_value, max_value)
elif basetype_content["name"] == "enum":
values = []
- for value in basetype_content["value"].values.getValue():
- values.append(value.getName())
+ for value in basetype_content["value"].values.getvalue():
+ values.append(value.getname())
datatype_def += " (%s)"%", ".join(values)
elif basetype_content["name"] == "array":
- base_type = basetype_content["value"].baseType.getContent()
+ base_type = basetype_content["value"].baseType.getcontent()
if base_type["name"] == "derived":
- basetype_name = base_type["value"].getName()
+ basetype_name = base_type["value"].getname()
elif base_type["name"] in ["string", "wstring"]:
basetype_name = base_type["name"].upper()
else:
basetype_name = base_type["name"]
GenerateDataType(basetype_name)
dimensions = []
- for dimension in basetype_content["value"].getDimension():
- dimensions.append("0..%d"%(dimension.getUpper() - 1))
+ for dimension in basetype_content["value"].getdimension():
+ dimensions.append("0..%d"%(dimension.getupper() - 1))
datatype_def += " ARRAY [%s] OF %s"%(",".join(dimensions), basetype_name)
else:
datatype_def += " %s"%basetype_content["name"]
if datatype.initialValue is not None:
- datatype_def += " := %s"%str(datatype.initialValue.getValue())
+ datatype_def += " := %s"%str(datatype.initialValue.getvalue())
currentProgram += "%s;\n"%datatype_def
def GeneratePouProgram(pou_name):
if not pouComputed.get(pou_name, True):
pouComputed[pou_name] = True
global currentProject, currentProgram
- pou = currentProject.getPou(pou_name)
- pou_type = pou.getPouType().getValue()
+ pou = currentProject.getpou(pou_name)
+ pou_type = pou.getpouType()
if pou_type in pouTypeNames:
- pou_program = PouProgram(pou.getName(), pouTypeNames[pou_type])
+ pou_program = PouProgram(pou.getname(), pouTypeNames[pou_type])
else:
raise ValueError, "Undefined pou type"
- pou_program.GenerateInterface(pou.getInterface())
+ pou_program.GenerateInterface(pou.getinterface())
pou_program.GenerateConnectionTypes(pou)
pou_program.GenerateProgram(pou)
currentProgram += pou_program.GenerateSTProgram()
def GenerateConfiguration(configuration):
- config = "\nCONFIGURATION %s\n"%configuration.getName()
- for varlist in configuration.getGlobalVars():
+ config = "\nCONFIGURATION %s\n"%configuration.getname()
+ for varlist in configuration.getglobalVars():
config += " VAR_GLOBAL"
- if varlist.getRetain():
+ if varlist.getretain():
config += " RETAIN"
- if varlist.getConstant():
+ if varlist.getconstant():
config += " CONSTANT"
config += "\n"
- for var in varlist.getVariable():
- vartype_content = var.getType().getContent()
+ for var in varlist.getvariable():
+ vartype_content = var.gettype().getcontent()
if vartype_content["name"] == "derived":
- var_type = vartype_content["value"].getName()
+ var_type = vartype_content["value"].getname()
elif vartype_content["name"] in ["string", "wstring"]:
var_type = vartype_content["name"].upper()
else:
var_type = vartype_content["name"]
- config += " %s "%var.getName()
- address = var.getAddress()
+ config += " %s "%var.getname()
+ address = var.getaddress()
if address:
config += "AT %s "%address
config += ": %s"%var_type
- initial = var.getInitialValue()
+ initial = var.getinitialValue()
if initial:
- value = str(initial.getValue())
+ value = str(initial.getvalue())
value = {"TRUE":"0","FALSE":"1"}.get(value.upper(), value)
if var_type == "STRING":
config += " := '%s'"%value
@@ -150,36 +154,36 @@
config += " := %s"%value
config += ";\n"
config += " END_VAR\n"
- for resource in configuration.getResource():
+ for resource in configuration.getresource():
config += GenerateResource(resource)
config += "END_CONFIGURATION\n"
return config
def GenerateResource(resource):
- resrce = "\n RESOURCE %s ON BEREMIZ\n"%resource.getName()
- for varlist in resource.getGlobalVars():
+ resrce = "\n RESOURCE %s ON BEREMIZ\n"%resource.getname()
+ for varlist in resource.getglobalVars():
resrce += " VAR_GLOBAL"
- if varlist.getRetain():
+ if varlist.getretain():
resrce += " RETAIN"
- if varlist.getConstant():
+ if varlist.getconstant():
resrce += " CONSTANT"
resrce += "\n"
- for var in varlist.getVariable():
- vartype_content = var.getType().getContent()
+ for var in varlist.getvariable():
+ vartype_content = var.gettype().getcontent()
if vartype_content["name"] == "derived":
- var_type = vartype_content["value"].getName()
+ var_type = vartype_content["value"].getname()
elif vartype_content["name"] in ["string", "wstring"]:
var_type = vartype_content["name"].upper()
else:
var_type = vartype_content["name"]
- resrce += " %s "%var.getName()
- address = var.getAddress()
+ resrce += " %s "%var.getname()
+ address = var.getaddress()
if address:
resrce += "AT %s "%address
resrce += ": %s"%var_type
- initial = var.getInitialValue()
+ initial = var.getinitialValue()
if initial:
- value = str(initial.getValue())
+ value = str(initial.getvalue())
value = {"TRUE":"0","FALSE":"1"}.get(value.upper(), value)
if var_type == "STRING":
resrce += " := '%s'"%value
@@ -189,14 +193,14 @@
resrce += " := %s"%value
resrce += ";\n"
resrce += " END_VAR\n"
- tasks = resource.getTask()
+ tasks = resource.gettask()
for task in tasks:
- resrce += " TASK %s("%task.getName()
+ resrce += " TASK %s("%task.getname()
args = []
- single = task.getSingle()
+ single = task.getsingle()
if single:
args.append("SINGLE := %s"%single)
- interval = task.getInterval()
+ interval = task.getinterval()
if interval:
text = "t#"
if interval.hour != 0:
@@ -208,13 +212,13 @@
if interval.microsecond != 0:
text += "%dms"%(interval.microsecond / 1000)
args.append("INTERVAL := %s"%text)
- args.append("PRIORITY := %s"%str(task.priority.getValue()))
+ args.append("PRIORITY := %s"%str(task.getpriority()))
resrce += ",".join(args) + ");\n"
for task in tasks:
- for instance in task.getPouInstance():
- resrce += " PROGRAM %s WITH %s : %s;\n"%(instance.getName(), task.getName(), instance.getType())
- for instance in resource.getPouInstance():
- resrce += " PROGRAM %s : %s;\n"%(instance.getName(), instance.getType())
+ for instance in task.getpouInstance():
+ resrce += " PROGRAM %s WITH %s : %s;\n"%(instance.getname(), task.getname(), instance.gettype())
+ for instance in resource.getpouInstance():
+ resrce += " PROGRAM %s : %s;\n"%(instance.getname(), instance.gettype())
resrce += " END_RESOURCE\n"
return resrce
@@ -258,40 +262,40 @@
return None
def GetConnectedConnection(self, connection, body):
- links = connection.getConnections()
+ links = connection.getconnections()
if links and len(links) == 1:
return self.GetLinkedConnection(links[0], body)
return None
def GetLinkedConnection(self, link, body):
- parameter = link.getFormalParameter()
- instance = body.getContentInstance(link.getRefLocalId())
- if isinstance(instance, (plcopen.inVariable, plcopen.inOutVariable, plcopen.continuation, plcopen.contact, plcopen.coil)):
+ parameter = link.getformalParameter()
+ instance = body.getcontentInstance(link.getrefLocalId())
+ if isinstance(instance, (plcopen.fbdObjects_inVariable, plcopen.fbdObjects_inOutVariable, plcopen.commonObjects_continuation, plcopen.ldObjects_contact, plcopen.ldObjects_coil)):
return instance.connectionPointOut
- elif isinstance(instance, plcopen.block):
- outputvariables = instance.outputVariables.getVariable()
+ elif isinstance(instance, plcopen.fbdObjects_block):
+ outputvariables = instance.outputVariables.getvariable()
if len(outputvariables) == 1:
return outputvariables[0].connectionPointOut
elif parameter:
for variable in outputvariables:
- if variable.getFormalParameter() == parameter:
+ if variable.getformalParameter() == parameter:
return variable.connectionPointOut
else:
point = link.getPosition()[-1]
for variable in outputvariables:
- relposition = variable.connectionPointOut.getRelPosition()
- blockposition = instance.getPosition()
+ relposition = variable.connectionPointOut.getrelPositionXY()
+ blockposition = instance.getposition()
if point.x == blockposition.x + relposition[0] and point.y == blockposition.y + relposition[1]:
return variable.connectionPointOut
- elif isinstance(instance, plcopen.leftPowerRail):
- outputconnections = instance.getConnectionPointOut()
+ elif isinstance(instance, plcopen.ldObjects_leftPowerRail):
+ outputconnections = instance.getconnectionPointOut()
if len(outputconnections) == 1:
return outputconnections[0]
else:
- point = link.getPosition()[-1]
+ point = link.getposition()[-1]
for outputconnection in outputconnections:
- relposition = outputconnection.getRelPosition()
- powerrailposition = instance.getPosition()
+ relposition = outputconnection.getrelPositionXY()
+ powerrailposition = instance.getposition()
if point.x == powerrailposition.x + relposition[0] and point.y == powerrailposition.y + relposition[1]:
return outputconnection
return None
@@ -304,106 +308,106 @@
def GenerateInterface(self, interface):
if self.Type == "FUNCTION":
- returntype_content = interface.getReturnType().getContent()
+ returntype_content = interface.getreturnType().getcontent()
if returntype_content["value"] is None:
self.ReturnType = returntype_content["name"]
else:
- self.ReturnType = returntype_content["value"].getName()
- for varlist in interface.getContent():
+ self.ReturnType = returntype_content["value"].getname()
+ for varlist in interface.getcontent():
variables = []
located = False
- for var in varlist["value"].getVariable():
- vartype_content = var.getType().getContent()
+ for var in varlist["value"].getvariable():
+ vartype_content = var.gettype().getcontent()
if vartype_content["name"] == "derived":
- var_type = vartype_content["value"].getName()
+ var_type = vartype_content["value"].getname()
GeneratePouProgram(var_type)
blocktype = GetBlockType(var_type)
if blocktype is not None:
- variables.extend(blocktype["initialise"](var_type, var.getName()))
+ variables.extend(blocktype["initialise"](var_type, var.getname()))
located = False
else:
- initial = var.getInitialValue()
+ initial = var.getinitialValue()
if initial:
- initial_value = initial.getValue()
+ initial_value = initial.getvalue()
else:
initial_value = None
- address = var.getAddress()
+ address = var.getaddress()
if address:
located = True
- variables.append((vartype_content["value"].getName(), var.getName(), address, initial_value))
+ variables.append((vartype_content["value"].getname(), var.getname(), address, initial_value))
else:
- initial = var.getInitialValue()
+ initial = var.getinitialValue()
if initial:
- initial_value = initial.getValue()
+ initial_value = initial.getvalue()
else:
initial_value = None
- address = var.getAddress()
+ address = var.getaddress()
if address:
located = True
if vartype_content["name"] in ["string", "wstring"]:
- variables.append((vartype_content["name"].upper(), var.getName(), address, initial_value))
+ variables.append((vartype_content["name"].upper(), var.getname(), address, initial_value))
else:
- variables.append((vartype_content["name"], var.getName(), address, initial_value))
+ variables.append((vartype_content["name"], var.getname(), address, initial_value))
if len(variables) > 0:
- self.Interface.append((varTypeNames[varlist["name"]], varlist["value"].getRetain(),
- varlist["value"].getConstant(), located, variables))
+ self.Interface.append((varTypeNames[varlist["name"]], varlist["value"].getretain(),
+ varlist["value"].getconstant(), located, variables))
def GenerateConnectionTypes(self, pou):
- body = pou.getBody()
- body_content = body.getContent()
+ body = pou.getbody()
+ body_content = body.getcontent()
body_type = body_content["name"]
if body_type in ["FBD", "LD", "SFC"]:
- for instance in body.getContentInstances():
- if isinstance(instance, (plcopen.inVariable, plcopen.outVariable, plcopen.inOutVariable)):
- expression = instance.getExpression()
+ for instance in body.getcontentInstances():
+ if isinstance(instance, (plcopen.fbdObjects_inVariable, plcopen.fbdObjects_outVariable, plcopen.fbdObjects_inOutVariable)):
+ expression = instance.getexpression()
var_type = self.GetVariableType(expression)
- if expression == pou.getName():
- returntype_content = pou.interface.getReturnType().getContent()
+ if expression == pou.getname():
+ returntype_content = pou.interface.getreturnType().getcontent()
if returntype_content["name"] == "derived":
- var_type = returntype_content["value"].getName()
+ var_type = returntype_content["value"].getname()
elif returntype_content["name"] in ["string", "wstring"]:
var_type = returntype_content["name"].upper()
else:
var_type = returntype_content["name"]
elif var_type is None:
var_type = expression.split("#")[0]
- if isinstance(instance, (plcopen.inVariable, plcopen.inOutVariable)):
+ if isinstance(instance, (plcopen.fbdObjects_inVariable, plcopen.fbdObjects_inOutVariable)):
self.ConnectionTypes[instance.connectionPointOut] = var_type
- if isinstance(instance, (plcopen.outVariable, plcopen.inOutVariable)):
+ if isinstance(instance, (plcopen.fbdObjects_outVariable, plcopen.fbdObjects_inOutVariable)):
self.ConnectionTypes[instance.connectionPointIn] = var_type
connected = self.GetConnectedConnection(instance.connectionPointIn, body)
if connected and connected not in self.ConnectionTypes:
for connection in self.ExtractRelatedConnections(connected):
self.ConnectionTypes[connection] = var_type
- elif isinstance(instance, (plcopen.contact, plcopen.coil)):
+ elif isinstance(instance, (plcopen.ldObjects_contact, plcopen.ldObjects_coil)):
self.ConnectionTypes[instance.connectionPointOut] = "BOOL"
self.ConnectionTypes[instance.connectionPointIn] = "BOOL"
connected = self.GetConnectedConnection(instance.connectionPointIn, body)
if connected and connected not in self.ConnectionTypes:
for connection in self.ExtractRelatedConnections(connected):
self.ConnectionTypes[connection] = "BOOL"
- elif isinstance(instance, plcopen.leftPowerRail):
- for connection in instance.getConnectionPointOut():
+ elif isinstance(instance, plcopen.ldObjects_leftPowerRail):
+ for connection in instance.getconnectionPointOut():
self.ConnectionTypes[connection] = "BOOL"
- elif isinstance(instance, plcopen.rightPowerRail):
- for connection in instance.getConnectionPointIn():
+ elif isinstance(instance, plcopen.ldObjects_rightPowerRail):
+ for connection in instance.getconnectionPointIn():
self.ConnectionTypes[connection] = "BOOL"
connected = self.GetConnectedConnection(connection, body)
if connected and connected not in self.ConnectionTypes:
for connection in self.ExtractRelatedConnections(connected):
self.ConnectionTypes[connection] = "BOOL"
- elif isinstance(instance, plcopen.transition):
- content = instance.condition.getContent()
+ elif isinstance(instance, plcopen.sfcObjects_transition):
+ content = instance.condition.getcontent()
if content["name"] == "connection" and len(content["value"]) == 1:
connected = self.GetLinkedConnection(content["value"][0], body)
if connected and connected not in self.ConnectionTypes:
for connection in self.ExtractRelatedConnections(connected):
self.ConnectionTypes[connection] = "BOOL"
- elif isinstance(instance, plcopen.block):
- block_infos = GetBlockType(instance.getTypeName())
+ elif isinstance(instance, plcopen.fbdObjects_block):
+ block_infos = GetBlockType(instance.gettypeName())
undefined = {}
- for variable in instance.outputVariables.getVariable():
- output_name = variable.getFormalParameter()
+ for variable in instance.outputVariables.getvariable():
+ output_name = variable.getformalParameter()
for oname, otype, oqualifier in block_infos["outputs"]:
if output_name == oname and variable.connectionPointOut not in self.ConnectionTypes:
if otype.startswith("ANY"):
@@ -413,8 +417,8 @@
else:
for connection in self.ExtractRelatedConnections(variable.connectionPointOut):
self.ConnectionTypes[connection] = otype
- for variable in instance.inputVariables.getVariable():
- input_name = variable.getFormalParameter()
+ for variable in instance.inputVariables.getvariable():
+ input_name = variable.getformalParameter()
for iname, itype, iqualifier in block_infos["inputs"]:
if input_name == iname:
connected = self.GetConnectedConnection(variable.connectionPointIn, body)
@@ -443,64 +447,64 @@
self.ConnectionTypes[connection] = var_type
def GenerateProgram(self, pou):
- body = pou.getBody()
- body_content = body.getContent()
+ body = pou.getbody()
+ body_content = body.getcontent()
body_type = body_content["name"]
if body_type in ["IL","ST"]:
- self.Program = ReIndentText(body_content["value"].getText(), 2)
+ self.Program = ReIndentText(body_content["value"].gettext(), 2)
elif body_type == "FBD":
orderedInstances = []
otherInstances = []
- for instance in body.getContentInstances():
- if isinstance(instance, (plcopen.outVariable, plcopen.inOutVariable, plcopen.block)):
- executionOrderId = instance.getExecutionOrderId()
+ for instance in body.getcontentInstances():
+ if isinstance(instance, (plcopen.fbdObjects_outVariable, plcopen.fbdObjects_inOutVariable, plcopen.fbdObjects_block)):
+ executionOrderId = instance.getexecutionOrderId()
if executionOrderId > 0:
orderedInstances.append((executionOrderId, instance))
else:
otherInstances.append(instance)
- elif isinstance(instance, plcopen.connector):
+ elif isinstance(instance, plcopen.commonObjects_connector):
otherInstances.append(instance)
orderedInstances.sort()
instances = [instance for (executionOrderId, instance) in orderedInstances] + otherInstances
for instance in instances:
- if isinstance(instance, (plcopen.outVariable, plcopen.inOutVariable)):
- var = instance.getExpression()
- connections = instance.connectionPointIn.getConnections()
+ if isinstance(instance, (plcopen.fbdObjects_outVariable, plcopen.fbdObjects_inOutVariable)):
+ var = instance.getexpression()
+ connections = instance.connectionPointIn.getconnections()
if connections and len(connections) == 1:
expression = self.ComputeFBDExpression(body, connections[0])
self.Program += " %s := %s;\n"%(var, expression)
- elif isinstance(instance, plcopen.block):
- block_type = instance.getTypeName()
+ elif isinstance(instance, plcopen.fbdObjects_block):
+ block_type = instance.gettypeName()
self.GeneratePouProgram(block_type)
block_infos = GetBlockType(block_type)
block_infos["generate"](self, instance, body, None)
- elif isinstance(instance, plcopen.connector):
- connector = instance.getName()
+ elif isinstance(instance, plcopen.commonObjects_connector):
+ connector = instance.getname()
if self.ComputedConnectors.get(connector, None):
continue
- connections = instance.connectionPointIn.getConnections()
+ connections = instance.connectionPointIn.getconnections()
if connections and len(connections) == 1:
self.ComputedConnectors[connector] = self.ComputeFBDExpression(body, connections[0])
elif body_type == "LD":
- for instance in body.getContentInstances():
- if isinstance(instance, plcopen.coil):
- paths = self.GenerateLDPaths(instance.connectionPointIn.getConnections(), body)
+ for instance in body.getcontentInstances():
+ if isinstance(instance, plcopen.ldObjects_coil):
+ paths = self.GenerateLDPaths(instance.connectionPointIn.getconnections(), body)
if len(paths) > 0:
paths = tuple(paths)
else:
paths = paths[0]
- variable = self.ExtractModifier(instance, instance.getVariable())
+ variable = self.ExtractModifier(instance, instance.getvariable())
expression = self.ComputeLDExpression(paths, True)
self.Program += " %s := %s;\n"%(variable, expression)
elif body_type == "SFC":
- for instance in body.getContentInstances():
- if isinstance(instance, plcopen.step):
+ for instance in body.getcontentInstances():
+ if isinstance(instance, plcopen.sfcObjects_step):
self.GenerateSFCStep(instance, pou)
- elif isinstance(instance, plcopen.actionBlock):
+ elif isinstance(instance, plcopen.commonObjects_actionBlock):
self.GenerateSFCStepActions(instance, pou)
- elif isinstance(instance, plcopen.transition):
+ elif isinstance(instance, plcopen.sfcObjects_transition):
self.GenerateSFCTransition(instance, pou)
- elif isinstance(instance, plcopen.jumpStep):
+ elif isinstance(instance, plcopen.sfcObjects_jumpStep):
self.GenerateSFCJump(instance, pou)
if len(self.InitialSteps) > 0 and self.SFCComputedBlocks != "":
action_name = "COMPUTE_FUNCTION_BLOCKS"
@@ -512,24 +516,24 @@
self.ComputeSFCStep(initialstep)
def ComputeFBDExpression(self, body, link, order = False):
- localid = link.getRefLocalId()
- instance = body.getContentInstance(localid)
- if isinstance(instance, (plcopen.inVariable, plcopen.inOutVariable)):
- return instance.getExpression()
- elif isinstance(instance, plcopen.block):
- block_type = instance.getTypeName()
+ localid = link.getrefLocalId()
+ instance = body.getcontentInstance(localid)
+ if isinstance(instance, (plcopen.fbdObjects_inVariable, plcopen.fbdObjects_inOutVariable)):
+ return instance.getexpression()
+ elif isinstance(instance, plcopen.fbdObjects_block):
+ block_type = instance.gettypeName()
self.GeneratePouProgram(block_type)
block_infos = GetBlockType(block_type)
return block_infos["generate"](self, instance, body, link, order)
- elif isinstance(instance, plcopen.continuation):
- name = instance.getName()
+ elif isinstance(instance, plcopen.commonObjects_continuation):
+ name = instance.getname()
computed_value = self.ComputedConnectors.get(name, None)
if computed_value != None:
return computed_value
- for tmp_instance in body.getContentInstances():
- if isinstance(tmp_instance, plcopen.connector):
- if tmp_instance.getName() == name:
- connections = tmp_instance.connectionPointIn.getConnections()
+ for tmp_instance in body.getcontentInstances():
+ if isinstance(tmp_instance, plcopen.commonObjects_connector):
+ if tmp_instance.getname() == name:
+ connections = tmp_instance.connectionPointIn.getconnections()
if connections and len(connections) == 1:
expression = self.ComputeFBDExpression(body, connections[0], order)
self.ComputedConnectors[name] = expression
@@ -539,18 +543,18 @@
def GenerateLDPaths(self, connections, body):
paths = []
for connection in connections:
- localId = connection.getRefLocalId()
- next = body.getContentInstance(localId)
- if isinstance(next, plcopen.leftPowerRail):
+ localId = connection.getrefLocalId()
+ next = body.getcontentInstance(localId)
+ if isinstance(next, plcopen.ldObjects_leftPowerRail):
paths.append(None)
- elif isinstance(next, plcopen.block):
- block_type = next.getTypeName()
+ elif isinstance(next, plcopen.fbdObjects_block):
+ block_type = next.gettypeName()
self.GeneratePouProgram(block_type)
block_infos = GetBlockType(block_type)
paths.append(block_infos["generate"](self, next, body, connection))
else:
- variable = self.ExtractModifier(next, next.getVariable())
- result = self.GenerateLDPaths(next.connectionPointIn.getConnections(), body)
+ variable = self.ExtractModifier(next, next.getvariable())
+ result = self.GenerateLDPaths(next.connectionPointIn.getconnections(), body)
if len(result) > 1:
paths.append([variable, tuple(result)])
elif type(result[0]) == ListType:
@@ -564,63 +568,63 @@
def GetNetworkType(self, connections, body):
network_type = "FBD"
for connection in connections:
- localId = connection.getRefLocalId()
- next = body.getContentInstance(localId)
- if isinstance(next, plcopen.leftPowerRail) or isinstance(next, plcopen.contact):
+ localId = connection.getrefLocalId()
+ next = body.getcontentInstance(localId)
+ if isinstance(next, plcopen.ldObjects_leftPowerRail) or isinstance(next, plcopen.ldObjects_contact):
return "LD"
- elif isinstance(next, plcopen.block):
- for variable in next.inputVariables.getVariable():
- result = self.GetNetworkType(variable.connectionPointIn.getConnections(), body)
+ elif isinstance(next, plcopen.fbdObjects_block):
+ for variable in next.inputVariables.getvariable():
+ result = self.GetNetworkType(variable.connectionPointIn.getconnections(), body)
if result != "FBD":
return result
- elif isinstance(next, plcopen.inVariable):
+ elif isinstance(next, plcopen.fbdObjects_inVariable):
return "FBD"
- elif isinstance(next, plcopen.inOutVariable):
- return self.GetNetworkType(next.connectionPointIn.getConnections(), body)
+ elif isinstance(next, plcopen.fbdObjects_inOutVariable):
+ return self.GetNetworkType(next.connectionPointIn.getconnections(), body)
else:
return None
return "FBD"
def ExtractDivergenceInput(self, divergence, pou):
- connectionPointIn = divergence.getConnectionPointIn()
+ connectionPointIn = divergence.getconnectionPointIn()
if connectionPointIn:
- connections = connectionPointIn.getConnections()
+ connections = connectionPointIn.getconnections()
if len(connections) == 1:
- instanceLocalId = connections[0].getRefLocalId()
- return pou.body.getContentInstance(instanceLocalId)
+ instanceLocalId = connections[0].getrefLocalId()
+ return pou.body.getcontentInstance(instanceLocalId)
return None
def ExtractConvergenceInputs(self, convergence, pou):
instances = []
- for connectionPointIn in convergence.getConnectionPointIn():
- connections = connectionPointIn.getConnections()
+ for connectionPointIn in convergence.getconnectionPointIn():
+ connections = connectionPointIn.getconnections()
if len(connections) == 1:
- instanceLocalId = connections[0].getRefLocalId()
- instances.append(pou.body.getContentInstance(instanceLocalId))
+ instanceLocalId = connections[0].getrefLocalId()
+ instances.append(pou.body.getcontentInstance(instanceLocalId))
return instances
def GenerateSFCStep(self, step, pou):
- step_name = step.getName()
+ step_name = step.getname()
if step_name not in self.SFCNetworks["Steps"].keys():
- if step.getInitialStep():
+ if step.getinitialStep():
self.InitialSteps.append(step_name)
- step_infos = {"initial" : step.getInitialStep(), "transitions" : [], "actions" : []}
+ step_infos = {"initial" : step.getinitialStep(), "transitions" : [], "actions" : []}
if step.connectionPointIn:
instances = []
- connections = step.connectionPointIn.getConnections()
+ connections = step.connectionPointIn.getconnections()
if len(connections) == 1:
- instanceLocalId = connections[0].getRefLocalId()
- instance = pou.body.getContentInstance(instanceLocalId)
- if isinstance(instance, plcopen.transition):
+ instanceLocalId = connections[0].getrefLocalId()
+ instance = pou.body.getcontentInstance(instanceLocalId)
+ if isinstance(instance, plcopen.sfcObjects_transition):
instances.append(instance)
- elif isinstance(instance, plcopen.selectionConvergence):
+ elif isinstance(instance, plcopen.sfcObjects_selectionConvergence):
instances.extend(self.ExtractConvergenceInputs(instance, pou))
- elif isinstance(instance, plcopen.simultaneousDivergence):
+ elif isinstance(instance, plcopen.sfcObjects_simultaneousDivergence):
transition = self.ExtractDivergenceInput(instance, pou)
if transition:
- if isinstance(transition, plcopen.transition):
+ if isinstance(transition, plcopen.sfcObjects_transition):
instances.append(transition)
- elif isinstance(transition, plcopen.selectionConvergence):
+ elif isinstance(transition, plcopen.sfcObjects_selectionConvergence):
instances.extend(self.ExtractConvergenceInputs(transition, pou))
for instance in instances:
self.GenerateSFCTransition(instance, pou)
@@ -629,23 +633,23 @@
self.SFCNetworks["Steps"][step_name] = step_infos
def GenerateSFCJump(self, jump, pou):
- jump_target = jump.getTargetName()
+ jump_target = jump.gettargetName()
if jump.connectionPointIn:
instances = []
- connections = jump.connectionPointIn.getConnections()
+ connections = jump.connectionPointIn.getconnections()
if len(connections) == 1:
- instanceLocalId = connections[0].getRefLocalId()
- instance = pou.body.getContentInstance(instanceLocalId)
- if isinstance(instance, plcopen.transition):
+ instanceLocalId = connections[0].getrefLocalId()
+ instance = pou.body.getcontentInstance(instanceLocalId)
+ if isinstance(instance, plcopen.sfcObjects_transition):
instances.append(instance)
- elif isinstance(instance, plcopen.selectionConvergence):
+ elif isinstance(instance, plcopen.sfcObjects_selectionConvergence):
instances.extend(self.ExtractConvergenceInputs(instance, pou))
- elif isinstance(instance, plcopen.simultaneousDivergence):
+ elif isinstance(instance, plcopen.sfcObjects_simultaneousDivergence):
transition = self.ExtractDivergenceInput(instance, pou)
if transition:
- if isinstance(transition, plcopen.transition):
+ if isinstance(transition, plcopen.sfcObjects_transition):
instances.append(transition)
- elif isinstance(transition, plcopen.selectionConvergence):
+ elif isinstance(transition, plcopen.sfcObjects_selectionConvergence):
instances.extend(self.ExtractConvergenceInputs(transition, pou))
for instance in instances:
self.GenerateSFCTransition(instance, pou)
@@ -653,14 +657,14 @@
self.SFCNetworks["Transitions"][instance]["to"].append(jump_target)
def GenerateSFCStepActions(self, actionBlock, pou):
- connections = actionBlock.connectionPointIn.getConnections()
+ connections = actionBlock.connectionPointIn.getconnections()
if len(connections) == 1:
- stepLocalId = connections[0].getRefLocalId()
- step = pou.body.getContentInstance(stepLocalId)
+ stepLocalId = connections[0].getrefLocalId()
+ step = pou.body.getcontentInstance(stepLocalId)
self.GenerateSFCStep(step, pou)
- step_name = step.getName()
+ step_name = step.getname()
if step_name in self.SFCNetworks["Steps"].keys():
- actions = actionBlock.getActions()
+ actions = actionBlock.getactions()
for action in actions:
action_infos = {"qualifier" : action["qualifier"], "content" : action["value"]}
if "duration" in action:
@@ -677,27 +681,27 @@
def GenerateSFCAction(self, action_name, pou):
if action_name not in self.SFCNetworks["Actions"].keys():
- actionContent = pou.getAction(action_name)
+ actionContent = pou.getaction(action_name)
if actionContent:
- actionType = actionContent.getBodyType()
- actionBody = actionContent.getBody()
+ actionType = actionContent.getbodyType()
+ actionBody = actionContent.getbody()
if actionType in ["ST", "IL"]:
- self.SFCNetworks["Actions"][action_name] = ReIndentText(actionContent.getText(), 4)
+ self.SFCNetworks["Actions"][action_name] = ReIndentText(actionContent.gettext(), 4)
elif actionType == "FBD":
- for instance in actionBody.getContentInstances():
- if isinstance(instance, plcopen.outVariable):
- var = instance.getExpression()
- connections = instance.connectionPointIn.getConnections()
+ for instance in actionBody.getcontentInstances():
+ if isinstance(instance, plcopen.fbdObjects_outVariable):
+ var = instance.getexpression()
+ connections = instance.connectionPointIn.getconnections()
if connections and len(connections) == 1:
expression = self.ComputeFBDExpression(actionBody, connections[0])
action_content = self.Program + " %s := %s;\n"%(var, expression)
self.Program = ""
self.SFCNetworks["Actions"][action_name] = ReIndentText(action_content, 4)
elif actionType == "LD":
- for instance in actionbody.getContentInstances():
- if isinstance(instance, plcopen.coil):
- paths = self.GenerateLDPaths(instance.connectionPointIn.getConnections(), actionBody)
- variable = self.ExtractModifier(instance, instance.getVariable())
+ for instance in actionbody.getcontentInstances():
+ if isinstance(instance, plcopen.ldObjects_coil):
+ paths = self.GenerateLDPaths(instance.connectionPointIn.getconnections(), actionBody)
+ variable = self.ExtractModifier(instance, instance.getvariable())
expression = self.ComputeLDExpression(paths, True)
action_content = self.Program + " %s := %s;\n"%(variable, expression)
self.Program = ""
@@ -706,53 +710,53 @@
def GenerateSFCTransition(self, transition, pou):
if transition not in self.SFCNetworks["Transitions"].keys():
steps = []
- connections = transition.connectionPointIn.getConnections()
+ connections = transition.connectionPointIn.getconnections()
if len(connections) == 1:
- instanceLocalId = connections[0].getRefLocalId()
- instance = pou.body.getContentInstance(instanceLocalId)
- if isinstance(instance, plcopen.step):
+ instanceLocalId = connections[0].getrefLocalId()
+ instance = pou.body.getcontentInstance(instanceLocalId)
+ if isinstance(instance, plcopen.sfcObjects_step):
steps.append(instance)
- elif isinstance(instance, plcopen.selectionDivergence):
+ elif isinstance(instance, plcopen.sfcObjects_selectionDivergence):
step = self.ExtractDivergenceInput(instance, pou)
if step:
- if isinstance(step, plcopen.step):
+ if isinstance(step, plcopen.sfcObjects_step):
steps.append(step)
- elif isinstance(step, plcopen.simultaneousConvergence):
+ elif isinstance(step, plcopen.sfcObjects_simultaneousConvergence):
steps.extend(self.ExtractConvergenceInputs(step, pou))
- elif isinstance(instance, plcopen.simultaneousConvergence):
+ elif isinstance(instance, plcopen.sfcObjects_simultaneousConvergence):
steps.extend(self.ExtractConvergenceInputs(instance, pou))
- transition_infos = {"priority": transition.getPriority(), "from": [], "to" : []}
- transitionValues = transition.getConditionContent()
+ transition_infos = {"priority": transition.getpriority(), "from": [], "to" : []}
+ transitionValues = transition.getconditionContent()
if transitionValues["type"] == "inline":
transition_infos["content"] = "\n := %s;\n"%transitionValues["value"]
elif transitionValues["type"] == "reference":
- transitionContent = pou.getTransition(transitionValues["value"])
- transitionType = transitionContent.getBodyType()
- transitionBody = transitionContent.getBody()
+ transitionContent = pou.gettransition(transitionValues["value"])
+ transitionType = transitionContent.getbodyType()
+ transitionBody = transitionContent.getbody()
if transitionType == "IL":
- transition_infos["content"] = ":\n%s"%ReIndentText(transitionBody.getText(), 4)
+ transition_infos["content"] = ":\n%s"%ReIndentText(transitionBody.gettext(), 4)
elif transitionType == "ST":
- transition_infos["content"] = "\n%s"%ReIndentText(transitionBody.getText(), 4)
+ transition_infos["content"] = "\n%s"%ReIndentText(transitionBody.gettext(), 4)
elif transitionType == "FBD":
- for instance in transitionBody.getContentInstances():
- if isinstance(instance, plcopen.outVariable):
- connections = instance.connectionPointIn.getConnections()
+ for instance in transitionBody.getcontentInstances():
+ if isinstance(instance, plcopen.fbdObjects_outVariable):
+ connections = instance.connectionPointIn.getconnections()
if connections and len(connections) == 1:
expression = self.ComputeFBDExpression(transitionBody, connections[0])
transition_infos["content"] = "\n := %s;\n"%expression
self.SFCComputedBlocks += self.Program
self.Program = ""
elif transitionType == "LD":
- for instance in transitionBody.getContentInstances():
- if isinstance(instance, plcopen.coil):
- paths = self.GenerateLDPaths(instance.connectionPointIn.getConnections(), transitionBody)
+ for instance in transitionBody.getcontentInstances():
+ if isinstance(instance, plcopen.ldObjects_coil):
+ paths = self.GenerateLDPaths(instance.connectionPointIn.getconnections(), transitionBody)
expression = self.ComputeLDExpression(paths, True)
transition_infos["content"] = "\n := %s;\n"%expression
self.SFCComputedBlocks += self.Program
self.Program = ""
elif transitionValues["type"] == "connection":
- body = pou.getBody()
- connections = transition.getConnections()
+ body = pou.getbody()
+ connections = transition.getconnections()
network_type = self.GetNetworkType(connections, body)
if network_type == None:
raise Exception
@@ -769,7 +773,7 @@
self.Program = ""
for step in steps:
self.GenerateSFCStep(step, pou)
- step_name = step.getName()
+ step_name = step.getname()
if step_name in self.SFCNetworks["Steps"].keys():
transition_infos["from"].append(step_name)
self.SFCNetworks["Steps"][step_name]["transitions"].append(transition)
@@ -840,15 +844,14 @@
return paths
def ExtractModifier(self, variable, text):
- if variable.getNegated():
+ if variable.getnegated():
return "NOT(%s)"%text
else:
- edge = variable.getEdge()
- if edge:
- if edge.getValue() == "rising":
- return self.AddTrigger("R_TRIG", text)
- elif edge.getValue() == "falling":
- return self.AddTrigger("F_TRIG", text)
+ edge = variable.getedge()
+ if edge == "rising":
+ return self.AddTrigger("R_TRIG", text)
+ elif edge == "falling":
+ return self.AddTrigger("F_TRIG", text)
return text
def AddTrigger(self, edge, text):
@@ -904,10 +907,10 @@
global currentProject, currentProgram
currentProject = project
currentProgram = ""
- for datatype in project.getDataTypes():
- datatypeComputed[datatype.getName()] = False
- for pou in project.getPous():
- pouComputed[pou.getName()] = False
+ for datatype in project.getdataTypes():
+ datatypeComputed[datatype.getname()] = False
+ for pou in project.getpous():
+ pouComputed[pou.getname()] = False
if len(datatypeComputed) > 0:
currentProgram += "TYPE\n"
for datatype_name in datatypeComputed.keys():
@@ -915,7 +918,7 @@
currentProgram += "END_TYPE\n\n"
for pou_name in pouComputed.keys():
GeneratePouProgram(pou_name)
- for config in project.getConfigurations():
+ for config in project.getconfigurations():
currentProgram += GenerateConfiguration(config)
return currentProgram