Overview of Structured Text Programming
652 Rockwell Automation Publication MOTION-RM002H-EN-P-February 2018
When selector is Enter
One value value: statement
Multiple, distinct values value1, value2, valueN : <statement>
Use a comma (,) to separate each value.
A range of values value1..valueN : <statement>
Use two periods (..) to identify the range.
Distinct values plus a range of values valuea, valueb, value1..valueN : <statement>
The CASE construct is similar to a switch statement in the C or C++
programming languages. However, with the CASE construct the controller
executes only the statements that are associated with the first matching selector
value. Execution always breaks after the statements of that selector and goes to the
END_CASE statement.
Affects Math Status Flags
No
Major/Minor Faults
None
Example
If you want this Enter this structured text
If recipe number = 1 then Ingredient A outlet 1 = open (1) Ingredient B
outlet 4 = open (1)
CASE recipe_number OF
1:
Ingredient_A.Outlet_1 :=1; Ingredient_B.Outlet_4 :=1;
If recipe number = 2 or 3 then
Ingredient A outlet 4 = open (1)
Ingredient B outlet 2 = open (1)
2,3:
Ingredient_A.Outlet_4 :=1; Ingredient_B.Outlet_2 :=1;
If recipe number = 4, 5, 6, or 7 then Ingredient A outlet 4 = open (1)
Ingredient B outlet 2 = open (1)
4 to 7: Ingredient_A.Outlet_4 :=1; Ingredient_B.Outlet_2 :=1;
If recipe number = 8, 11, 12, or 13 then Ingredient A outlet 1 = open (1)
Ingredient B outlet 4 = open (1)
8,11…13
Ingredient_A.Outlet_1 :=1; Ingredient_B.Outlet_4 :=1;
Otherwise all outlets = closed (0) ELSE
Ingredient_A.Outlet_1 [:=]0; Ingredient_A.Outlet_4 [:=]0; Ingredient_B.Outlet_2 [:=]0;
Ingredient_B.Outlet_4 [:=]0;
END_CASE;
The [:=] tells the controller to also clear the outlet tags whenever the controller
does the following:
Enters the RUN mode.