I am currently programming/simulating a small plant in CODESYS. I have several outputs (that correspond to engines) that I need to test several times, so I want to create a condition that incorporates this test so I dont need to write the entire condition. For instance, i have the condition that verifies if
A=TRUE AND B=TRUE AND C=TRUE AND D=TRUE
Can I create a condition like "verify engine" to use each time ?
Thank you
There are many ways to do this (if I understood you correctly).
Here are two ways for example:
1. Create a variable that has the condition result and use the variable. You have to assign the variable at beginning, and then you can use the variable instead of that long code.
2. Create a function, for example
F_VerifyEngines
that contains checks and returns the state asBOOL
. Note: In this example A,B,C and D need to be global variables. You could also pass them as parameters for the function.Then you can use the function in code:
The 2nd way is probably the one you were thinking.
By the way, there is no need to write
A = TRUE AND B = TRUE AND C = TRUE AND D = TRUE
, in my opinion, it's more clear to read when you useA AND B AND C AND D
instead.