--- a/PLCGenerator.py Tue Jul 31 14:17:41 2018 +0300
+++ b/PLCGenerator.py Wed Aug 01 13:09:45 2018 +0300
@@ -900,6 +900,42 @@
for connection in related:
self.ConnectionTypes[connection] = var_type
+ def GetUsedEno(self, body, connections): + Function checks whether value on given connection + comes from block, that has used EN input and + returns variable name for ENO output. + This is needed to avoid value propagation from blocks + with false signal on EN input. + body of the block for that program is currently generated + connection, that's source is checked for EN/ENO usage + if EN/ENO are not used, then None is returned + Otherwise BOOL variable corresponding to ENO + if len(connections) != 1: + ref_local_id = connections[0].getrefLocalId() + blk = body.getcontentInstance(ref_local_id) + for invar in blk.inputVariables.getvariable(): + if invar.getformalParameter() == "EN": + if len(invar.getconnectionPointIn().getconnections()) > 0: + if blk.getinstanceName() is None: + var_name = "%s%d_ENO" % (blk.gettypeName(), blk.getlocalId()) + var_name = "%s.ENO" % blk.getinstanceName() def ComputeProgram(self, pou):
if isinstance(body, ListType):
@@ -958,11 +994,21 @@
if connections is not None:
expression = self.ComputeExpression(body, connections)
if expression is not None:
+ eno_var = self.GetUsedEno(body, connections) + if eno_var is not None: + self.Program += [(self.CurrentIndent + "IF %s" % eno_var, ())] + self.Program += [(" THEN\n ", ())] self.Program += [(self.CurrentIndent, ()),
(instance.getexpression(), (self.TagName, "io_variable", instance.getlocalId(), "expression")),
self.Program += expression
self.Program += [(";\n", ())]
+ if eno_var is not None: + self.Program += [(self.CurrentIndent + "END_IF;\n", ())] elif isinstance(instance, BlockClass):
block_type = instance.gettypeName()
self.ParentGenerator.GeneratePouProgram(block_type)