--- a/PLCGenerator.py Wed Apr 16 09:45:15 2008 +0200
+++ b/PLCGenerator.py Wed Apr 16 09:46:56 2008 +0200
@@ -475,18 +475,21 @@
self.Program = ReIndentText(body_content["value"].gettext(), 2)
elif body_type == "FBD":
orderedInstances = []
- otherInstances = []
+ otherInstances = {"outVariables" : [], "block" : [], "connector" : []}
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.fbdObjects_outVariable, plcopen.fbdObjects_inOutVariable)):
+ otherInstances["outVariables"].append(instance)
+ elif isinstance(instance, plcopen.fbdObjects_block):
+ otherInstances["block"].append(instance)
elif isinstance(instance, plcopen.commonObjects_connector):
- otherInstances.append(instance)
+ otherInstances["connector"].append(instance)
orderedInstances.sort()
- instances = [instance for (executionOrderId, instance) in orderedInstances] + otherInstances
+ instances = [instance for (executionOrderId, instance) in orderedInstances]
+ instances.extend(otherInstances["connector"] + otherInstances["outVariables"] + otherInstances["block"])
for instance in instances:
if isinstance(instance, (plcopen.fbdObjects_outVariable, plcopen.fbdObjects_inOutVariable)):
var = instance.getexpression()
@@ -610,7 +613,7 @@
connectionPointIn = divergence.getconnectionPointIn()
if connectionPointIn:
connections = connectionPointIn.getconnections()
- if len(connections) == 1:
+ if connections is not None and len(connections) == 1:
instanceLocalId = connections[0].getrefLocalId()
return pou.body.getcontentInstance(instanceLocalId)
return None
@@ -679,7 +682,7 @@
def GenerateSFCStepActions(self, actionBlock, pou):
connections = actionBlock.connectionPointIn.getconnections()
- if len(connections) == 1:
+ if connections is not None and len(connections) == 1:
stepLocalId = connections[0].getrefLocalId()
step = pou.body.getcontentInstance(stepLocalId)
self.GenerateSFCStep(step, pou)
@@ -732,7 +735,7 @@
if transition not in self.SFCNetworks["Transitions"].keys():
steps = []
connections = transition.connectionPointIn.getconnections()
- if len(connections) == 1:
+ if connections is not None and len(connections) == 1:
instanceLocalId = connections[0].getrefLocalId()
instance = pou.body.getcontentInstance(instanceLocalId)
if isinstance(instance, plcopen.sfcObjects_step):
@@ -836,13 +839,17 @@
self.Program += " FROM "
if len(transition_infos["from"]) > 1:
self.Program += "(%s)"%", ".join(transition_infos["from"])
- else:
+ elif len(transition_infos["from"]) == 1:
self.Program += "%s"%transition_infos["from"][0]
+ else:
+ raise PLCGenException, "Not connected transition"
self.Program += " TO "
if len(transition_infos["to"]) > 1:
self.Program += "(%s)"%", ".join(transition_infos["to"])
- else:
+ elif len(transition_infos["to"]) == 1:
self.Program += "%s"%transition_infos["to"][0]
+ else:
+ raise PLCGenException, "Not connected transition"
self.Program += transition_infos["content"]
self.Program += " END_TRANSITION\n\n"
for step_name in transition_infos["to"]: