
Parker Hannifin
Programming Basics 55
WHILE/WEND
The WHILE/WEND loop executes as long as its condition remains true.
You can use the WHLE/WEND anywhere in a program.
The WHILE sets the condition, and is followed by statements you
want executed when the condition is true. When the condition is
false, the statement immediately following WEND executes. The
condition is evaluated only at the beginning of the loop.
When using a WHILE/WEND statement, observe the following:
• Do not nest GOTO statements in an WHILE/WEND statement.
• At the start of each loop through the WHILE condition, the
validity of the condition is tested.
Example
The following demonstrates a WHILE/WEND loop. While the encoder
position for axis 2 is less than 1500 units, the WHILE statement
evaluates as true. As the loop runs, the array acts as a counter,
incrementing with each loop; axis X move an incremental 25 units;
the program pauses for 1.5 seconds, then prints the current value of
the array; and if the input (bit 24) is set the loop breaks. When the
encoder count exceeds 1500, the condition is false and execution
moves past the WEND statement.
WHILE (P6176 < 1500)
LA0(1) = LA0(1) + 1
X/25
DWL 1.5
PRINT LA0(1)
IF (BIT 24)
BREAK
ENDIF
WEND
Other Conditional Statements
There are two additional program flow control commands: INH and
IHPOS. The INH command lets you inhibit (pause) program execution
until the state of a selected bit (set or clear) occurs. Similarly, the
IHPOS command lets you inhibit program execution until a specific
axis position is occurs.
INH
The INH command lets you inhibit program execution based on the
set or clear state of a specified bit.
NOTE: Do not use INH in non-motion programs. If you have multiple
non-motion programs, an inhibit in one non-motion program
affects all non-motion programs.
Commentaires sur ces manuels