User`s guide
Recursive Programs
Recursive programs are subroutines that call themselves, either directly or indirectly. A direct
call occurs when a program actually calls itself, which is useful for some special programming
situations. Indirect calls are more common. They occur when program A calls program B,
which eventually leads to another call to program A before program B returns. For example,
an output routine may detect an error and call an error-handling routine, which in turn calls
the original output routine to report the error.
If recursive subroutine calls are used, the program must observe the same guidelines as for
reentrant programs (see Reentrant Programs on page 45). In addition, you must guarantee
that the recursive calls do not continue indefinitely. Otherwise, the program task will run out
of stack space.
Asynchronous Processing
A particularly powerful feature of V+ is the ability to respond to an event (such as an external
signal or error condition) when it occurs, without the programmer's having to include
instructions to test repeatedly for the event. If event handling is properly enabled, V+ will
react to an event by invoking a specified program just as if a CALL instruction had been
executed. Such a program is said to be called asynchronously, since its execution is not
synchronized with the normal program flow.
Asynchronous processing is enabled by the REACT, REACTE, and REACTI program
instructions. Each program task can use these instructions to prepare for independent
processing of events. In addition, the optional V+ Extensions software uses the WINDOW
instruction to enable asynchronous processing of window violations when the robot is
tracking a conveyor belt.
Sometimes a reaction must be delayed until a critical program section has completed. Also,
since some events are more important than others, a program should be able to react to
some events but not others. V+ allows the relative importance of a reaction to be specified by
a program priority value from 1 to 127. The higher the program priority setting, the more
important is the reaction.
A reaction subroutine is called only if the main program priority is less than that of the
reaction program priority. If the main program priority is greater than or equal to the reaction
program priority, execution of the reaction subroutine is deferred until the main program
priority drops. Since the main program (for example, the robot control program) normally
runs at program priority zero and the minimum reaction program priority is one, any reaction
can normally interrupt the main program.
The main program priority can be raised or lowered with the LOCK program instruction, and
its current value can be determined with the PRIORITY real-valued function. When the main
program priority is raised to a certain value, all reactions of equal or lower priority are locked
out.
When a reaction subroutine is called, the main program priority is automatically set to the
reaction program priority, thus preventing any reactions of equal or lower program priority
Subroutines
V+Language User's Guide, v17.0
Page 46










