Exploring the CASE statement
If you’ve ever programmed in a language such as C/C++, Java, C#, or any other modern programming language, you might be familiar with a SWITCH
statement. The IEC 61131-3 standard doesn’t support a SWITCH
statement per se, but it does support a CASE
statement, which is, for all purposes, the same. The CASE
statement is like the IF
statement, except it requires less overhead in terms of code. However, there is a drawback to the CASE
statement in that it can only check for equality. This makes the CASE
statement ideal for applications that require comparison of data such as status codes but less than ideal for applications that check for inequality.
State machines and CASE statements
A common application for the CASE
statement is what is known as a state machine. State machines are an advanced concept that are only going to be touched on here. There is a lot of theory that needs to be understood to fully understand state machines. Therefore...