Fixed bug when generating ST code and connection is broken in POU using graphical language
--- a/PLCGenerator.py Mon Jun 10 09:54:24 2013 +0200
+++ b/PLCGenerator.py Mon Jun 10 11:22:05 2013 +0200
@@ -900,11 +900,12 @@
connections = instance.connectionPointIn.getconnections()
if connections is not None:
expression = self.ComputeExpression(body, connections)
- self.Program += [(self.CurrentIndent, ()),
- (instance.getexpression(), (self.TagName, "io_variable", instance.getlocalId(), "expression")),
- (" := ", ())]
- self.Program += expression
- self.Program += [(";\n", ())]
+ if expression is not None:
+ self.Program += [(self.CurrentIndent, ()),
+ (instance.getexpression(), (self.TagName, "io_variable", instance.getlocalId(), "expression")),
+ (" := ", ())]
+ self.Program += expression
+ self.Program += [(";\n", ())]
elif isinstance(instance, plcopen.fbdObjects_block):
block_type = instance.gettypeName()
self.ParentGenerator.GeneratePouProgram(block_type)
@@ -920,16 +921,20 @@
elif isinstance(instance, plcopen.commonObjects_connector):
connector = instance.getname()
if self.ComputedConnectors.get(connector, None):
- continue
- self.ComputedConnectors[connector] = self.ComputeExpression(body, instance.connectionPointIn.getconnections())
+ continue
+ expression = self.ComputeExpression(body, instance.connectionPointIn.getconnections())
+ if expression is not None:
+ self.ComputedConnectors[connector] = expression
elif isinstance(instance, plcopen.ldObjects_coil):
connections = instance.connectionPointIn.getconnections()
if connections is not None:
coil_info = (self.TagName, "coil", instance.getlocalId())
- expression = self.ExtractModifier(instance, self.ComputeExpression(body, connections), coil_info)
- self.Program += [(self.CurrentIndent, ())]
- self.Program += [(instance.getvariable(), coil_info + ("reference",))]
- self.Program += [(" := ", ())] + expression + [(";\n", ())]
+ expression = self.ComputeExpression(body, connections)
+ if expression is not None:
+ expression = self.ExtractModifier(instance, expression, coil_info)
+ self.Program += [(self.CurrentIndent, ())]
+ self.Program += [(instance.getvariable(), coil_info + ("reference",))]
+ self.Program += [(" := ", ())] + expression + [(";\n", ())]
def FactorizePaths(self, paths):
same_paths = {}
@@ -995,8 +1000,9 @@
connections = connector.connectionPointIn.getconnections()
if connections is not None:
expression = self.ComputeExpression(body, connections, order)
- self.ComputedConnectors[name] = expression
- paths.append(str(expression))
+ if expression is not None:
+ self.ComputedConnectors[name] = expression
+ paths.append(str(expression))
else:
raise PLCGenException, _("No connector found corresponding to \"%s\" continuation in \"%s\" POU")%(name, self.Name)
elif isinstance(next, plcopen.ldObjects_contact):
@@ -1039,6 +1045,8 @@
def ComputeExpression(self, body, connections, order = False, to_inout = False):
paths = self.GeneratePaths(connections, body, order, to_inout)
+ if len(paths) == 0:
+ return None
if len(paths) > 1:
factorized_paths = self.FactorizePaths(paths)
if len(factorized_paths) > 1:
@@ -1262,9 +1270,10 @@
connections = instance.connectionPointIn.getconnections()
if connections is not None:
expression = self.ComputeExpression(transitionBody, connections)
- transition_infos["content"] = [("\n%s:= "%self.CurrentIndent, ())] + expression + [(";\n", ())]
- self.SFCComputedBlocks += self.Program
- self.Program = []
+ if expression is not None:
+ transition_infos["content"] = [("\n%s:= "%self.CurrentIndent, ())] + expression + [(";\n", ())]
+ self.SFCComputedBlocks += self.Program
+ self.Program = []
if not transition_infos.has_key("content"):
raise PLCGenException, _("Transition \"%s\" body must contain an output variable or coil referring to its name") % transitionValues["value"]
self.TagName = previous_tagname
@@ -1275,9 +1284,10 @@
connections = transition.getconnections()
if connections is not None:
expression = self.ComputeExpression(body, connections)
- transition_infos["content"] = [("\n%s:= "%self.CurrentIndent, ())] + expression + [(";\n", ())]
- self.SFCComputedBlocks += self.Program
- self.Program = []
+ if expression is not None:
+ transition_infos["content"] = [("\n%s:= "%self.CurrentIndent, ())] + expression + [(";\n", ())]
+ self.SFCComputedBlocks += self.Program
+ self.Program = []
for step in steps:
self.GenerateSFCStep(step, pou)
step_name = step.getname()
--- a/plcopen/structures.py Mon Jun 10 09:54:24 2013 +0200
+++ b/plcopen/structures.py Mon Jun 10 11:22:05 2013 +0200
@@ -87,12 +87,14 @@
if parameter != "EN":
one_input_connected = True
if inout_variables.has_key(parameter):
- value = generator.ComputeExpression(body, connections, executionOrderId > 0, True)
- inout_variables[parameter] = value
+ expression = generator.ComputeExpression(body, connections, executionOrderId > 0, True)
+ if expression is not None:
+ inout_variables[parameter] = value
else:
- value = generator.ComputeExpression(body, connections, executionOrderId > 0)
- connected_vars.append(([(parameter, input_info), (" := ", ())],
- generator.ExtractModifier(variable, value, input_info)))
+ expression = generator.ComputeExpression(body, connections, executionOrderId > 0)
+ if expression is not None:
+ connected_vars.append(([(parameter, input_info), (" := ", ())],
+ generator.ExtractModifier(variable, expression, input_info)))
else:
all_input_connected = False
else:
@@ -146,9 +148,10 @@
input_info = (generator.TagName, "block", block.getlocalId(), "input", input_idx)
connections = variable.connectionPointIn.getconnections()
if connections is not None:
- value = generator.ComputeExpression(body, connections, executionOrderId > 0, inout_variables.has_key(parameter))
- vars.append([(parameter, input_info),
- (" := ", ())] + generator.ExtractModifier(variable, value, input_info))
+ expression = generator.ComputeExpression(body, connections, executionOrderId > 0, inout_variables.has_key(parameter))
+ if expression is not None:
+ vars.append([(parameter, input_info),
+ (" := ", ())] + generator.ExtractModifier(variable, expression, input_info))
generator.Program += [(generator.CurrentIndent, ()),
(name, (generator.TagName, "block", block.getlocalId(), "name")),
("(", ())]