![Galil Motion Control RIO-47 series
RIO-47100 User Manual Download Page 64](http://html1.mh-extra.com/html/galil-motion-control/rio-47-series-rio-47100/rio-47-series-rio-47100_user-manual_558776064.webp)
Nesting IF Conditional Statements
The RIO allows for IF conditional statements to be included within other IF conditional statements.
This technique is known as 'nesting' and the RIO allows up to 255 IF conditional statements to be
nested. This is a very powerful technique allowing the user to specify a variety of different cases for
branching.
Command Format - IF, ELSE and ENDIF
Function
Condition
IF conditional statement(s)
Execute commands proceeding IF command (up to ELSE command) if
conditional statement(s) is true, otherwise continue executing at ENDIF
command or optional ELSE command.
ELSE
Optional command. Allows for commands to be executed when argument of IF
command evaluates not true. Can only be used with IF command.
ENDIF
Command to end IF conditional statement. Program must have an ENDIF
command for every IF command.
Example using IF, ELSE and ENDIF:
Instruction
Interpretation
#TEST
Begin Main Program "TEST"
#LOOP
Begin loop inside main program
TEMP=@IN[1]|@IN[2]
TEMP is equal to 1 if either Input 1 or Input 2 is high
JS#COND, TEMP=1
Jump to subroutine if TEMP equals 1
JP#LOOP
Loop back if TEMP doesn’t equal 1
EN
End of main program
#COND
Begin subroutine “COND”
IF (@IN[1]=0)
IF conditional statement based on input 1
IF (@IN[2]=0)
2
nd
IF conditional statement executed if 1
st
IF conditional
true
MG "INPUT 1 AND INPUT 2 ARE
INACTIVE"
Message to be executed if 2
nd
IF conditional is true
ELSE
ELSE command for 2
nd
IF conditional statement
MG "ONLY INPUT 1 IS ACTIVE”
Message to be executed if 2
nd
IF conditional is false
ENDIF
End of 2
nd
conditional statement
ELSE
ELSE command for 1
st
IF conditional statement
MG"ONLY INPUT 2 IS ACTIVE"
Message to be executed if 1
st
IF conditional statement
ENDIF
End of 1
st
conditional statement
#WAIT
Label to be used for a loop
JP#WAIT,(@IN[1]=0) & (@IN[2]=0)
Loop until both input 1 and input 2 are not active
EN
End of subroutine
Stack Manipulation
It is possible to manipulate the subroutine stack by using the ZS command. Every time a JS
instruction, interrupt or automatic routine (such as #ININTn or #CMDERR) is executed, the subroutine
stack is incremented by 1 (up to a maximum of 16). Normally the stack is restored with an EN
instruction. Occasionally it is desirable not to return back to the program line where the subroutine
or interrupt was called. The ZS1 command clears 1 level of the stack. This allows the program
sequencer to continue to the next line. The ZS0 command resets the stack to its initial value. For
example, if an interrupt occurs and the #ININT1 routine is executed, it may be desirable to restart the
program sequence instead of returning to the location where the interrupt occurred. To do this, give
a ZS (ZS0) command at the end of the #ININT1 routine.
Chapter 5 Programming ▫ 64 RIO-47xxx Rev. 1.0r