The documentation for ST's operators says that the comparison and equality operators <
, >
, <=
, >=
, =
, and <>
have a higher precedence than boolean logic operators and bitwise logic operators.
Also, in ST bitwise logic operators are AND
and OR
instead of &
and |
. Similarly, the boolean logic operators are AND_THEN
and OR_ELSE
instead of &&
and ||
. (beware though, that the boolean logic operator were added to CODESYS compiler V3.5 SP4, if you are using an older one, they won't be available. For example, SoMachine uses an older one)
Additionally, the syntax for IF
is as follows:
IF condition THEN
statement1;
ELSEIF condition THEN
statement2;
ELSE
statement3;
END_IF;
But your code has ELSE IF
instead of ELSEIF
and your END_IF
is lacking a semicolon. (Though I have never had any compiler complain if I skipped that, and they themselves often omit them in their examples in the documentation)
So, you just need to parenthesize the bitwise operation before the comparison. (It's the same situation in C-family languages too, which leads to unreadable expressions with too many parentheses), replace them with valid ST operators, and fix the ELSE IF
part.
Try incorporating those changes, like so:
(Note I also added whitespace for readability. ST does not impose any semantics on whitespace (unlike Python, Haskell, etc) so you should use whitespace to maximize readability and maintainability). (My personal style is to have spaces within parentheses, not outside them - other people strongly disagree, YMMV)
IF ( ( Rx_test_1 AND 4 ) = 4 ) THEN
out ( OUT_1_POH_CL, 1500 );
ELSEIF ( ( Rx_test_1 AND 8 ) = 8 ) THEN
out ( OUT_1_POH_CL, 0 );
END_IF;