LadderLogic
Member
While working with Omron CX-P writing some code in structured text, I ran into a question for which I cannot seem to find a clear answer. It regards the operation of CASE...END_CASE statement. Here is an example:
CASE A OF
1:X:=1;
2:X:=2;
3:X:=3;
ELSE Y:=0;
END_CASE;
No misteries here: the variable A is evaluated and the program skips to one of the CASE clauses that matches the value of A (if A = 1 then X := 1 and so on). Once that clause is executed, the program flow jumps to END_CASE and then to whatever follows it.
Now consider this:
CASE A OF
1:
X:=1;
A:=2;
2:X:=2;
3:X:=3;
ELSE Y:=0;
END_CASE;
What happens when A equals 1? Obviously, the first clause would be executed, X would be assigned value of 1, A would be assigned value of 2 and then... And then - what? Would the program flow still jump directly to END_CASE and the new value of A will come into effect only on the next program scan or would the second clause (A = 2) would execute immediately?
The first is true for Select Case... End Select construct in Visual Basic. Is IEC STL CASE construct works the same or does it follow a typical ladder code assumption that evaluates every line of code top-to-bottom left-to-right?
P.S. As I mentioned above, I have been working with Omron's version of STL which may not be 100% IEC-compliant.