Beckhoff Automation GmbH & Co. KG TX1200 — 2.2.3.1 FOR loop

A Brief Introduction to TwinCAT PLC Control The same loop programmed in ST would produce: WHILE Counter 0 DO Var1:=Var1*2; Counter:=Counter-1; END_WHILE Erg:=Var1; You can see, the loop in ST is not only faster to program, but is also significantly easier to read, especially in view of the convoluted loops in larger constructs. The different structures in ST have the following significance: Assignment operator On the left side of an assignment there is an operand (variable, address) to which is assigned the value of the expression on the right side with the assignment operator := Example: Var1 := Var2 * 10; After completion of this line Var1 has the tenfold value of Var2.

Calling function blocks in ST A function block is called in ST by writing the name of the instance of the function block and then assigning the values of the parameters in parentheses. In the following example a timer is called with assignments for the parameters IN and PT. Then the result variable Q is assigned to the variable A. The result variable, as in IL, is addressed with the name of the function block, a following point, and the name of the variable: CMD_TMR(IN := %IX5, PT := 300); A:=CMD_TMR.Q 2.2.3.1 FOR loop With the FOR loop one can program repeated processes. Syntax: INT_Var :INT; FOR := TO {BY } DO END_FOR; The part in braces {} is optional.

The are executed as long as the counter is not greater than the . This is checked before executing the so that the are never executed if is greater than . When are executed, is always increased by . The step size can have any integer value. If it is missing, then it is set to 1. The loop must also end since only becomes greater. Example: FOR counter:=1 TO 5 BY 1 DO Var1:=Var1*2; END_FOR; Erg:=Var1; TX1200 20 Version: 1.3