898 self.RelatedConnections.append(related) |
898 self.RelatedConnections.append(related) |
899 else: |
899 else: |
900 for connection in related: |
900 for connection in related: |
901 self.ConnectionTypes[connection] = var_type |
901 self.ConnectionTypes[connection] = var_type |
902 |
902 |
|
903 def GetUsedEno(self, body, connections): |
|
904 """ |
|
905 Function checks whether value on given connection |
|
906 comes from block, that has used EN input and |
|
907 returns variable name for ENO output. |
|
908 |
|
909 This is needed to avoid value propagation from blocks |
|
910 with false signal on EN input. |
|
911 |
|
912 :param body: |
|
913 body of the block for that program is currently generated |
|
914 :param connections: |
|
915 connection, that's source is checked for EN/ENO usage |
|
916 :return: |
|
917 if EN/ENO are not used, then None is returned |
|
918 Otherwise BOOL variable corresponding to ENO |
|
919 output is returned. |
|
920 """ |
|
921 |
|
922 if len(connections) != 1: |
|
923 return None |
|
924 ref_local_id = connections[0].getrefLocalId() |
|
925 blk = body.getcontentInstance(ref_local_id) |
|
926 if blk is None: |
|
927 return None |
|
928 |
|
929 for invar in blk.inputVariables.getvariable(): |
|
930 if invar.getformalParameter() == "EN": |
|
931 if len(invar.getconnectionPointIn().getconnections()) > 0: |
|
932 if blk.getinstanceName() is None: |
|
933 var_name = "%s%d_ENO" % (blk.gettypeName(), blk.getlocalId()) |
|
934 else: |
|
935 var_name = "%s.ENO" % blk.getinstanceName() |
|
936 return var_name |
|
937 return None |
|
938 |
903 def ComputeProgram(self, pou): |
939 def ComputeProgram(self, pou): |
904 body = pou.getbody() |
940 body = pou.getbody() |
905 if isinstance(body, ListType): |
941 if isinstance(body, ListType): |
906 body = body[0] |
942 body = body[0] |
907 body_content = body.getcontent() |
943 body_content = body.getcontent() |
956 if isinstance(instance, (OutVariableClass, InOutVariableClass)): |
992 if isinstance(instance, (OutVariableClass, InOutVariableClass)): |
957 connections = instance.connectionPointIn.getconnections() |
993 connections = instance.connectionPointIn.getconnections() |
958 if connections is not None: |
994 if connections is not None: |
959 expression = self.ComputeExpression(body, connections) |
995 expression = self.ComputeExpression(body, connections) |
960 if expression is not None: |
996 if expression is not None: |
|
997 eno_var = self.GetUsedEno(body, connections) |
|
998 if eno_var is not None: |
|
999 self.Program += [(self.CurrentIndent + "IF %s" % eno_var, ())] |
|
1000 self.Program += [(" THEN\n ", ())] |
|
1001 self.IndentRight() |
|
1002 |
961 self.Program += [(self.CurrentIndent, ()), |
1003 self.Program += [(self.CurrentIndent, ()), |
962 (instance.getexpression(), (self.TagName, "io_variable", instance.getlocalId(), "expression")), |
1004 (instance.getexpression(), (self.TagName, "io_variable", instance.getlocalId(), "expression")), |
963 (" := ", ())] |
1005 (" := ", ())] |
964 self.Program += expression |
1006 self.Program += expression |
965 self.Program += [(";\n", ())] |
1007 self.Program += [(";\n", ())] |
|
1008 |
|
1009 if eno_var is not None: |
|
1010 self.IndentLeft() |
|
1011 self.Program += [(self.CurrentIndent + "END_IF;\n", ())] |
966 elif isinstance(instance, BlockClass): |
1012 elif isinstance(instance, BlockClass): |
967 block_type = instance.gettypeName() |
1013 block_type = instance.gettypeName() |
968 self.ParentGenerator.GeneratePouProgram(block_type) |
1014 self.ParentGenerator.GeneratePouProgram(block_type) |
969 block_infos = self.GetBlockType(block_type, tuple([self.ConnectionTypes.get(variable.connectionPointIn, "ANY") for variable in instance.inputVariables.getvariable() if variable.getformalParameter() != "EN"])) |
1015 block_infos = self.GetBlockType(block_type, tuple([self.ConnectionTypes.get(variable.connectionPointIn, "ANY") for variable in instance.inputVariables.getvariable() if variable.getformalParameter() != "EN"])) |
970 if block_infos is None: |
1016 if block_infos is None: |