Text Language Definition
procedure ScheduleTask(TaskAddress:pointer; Period:longint);
Description
This command causes a procedure in the controller to periodically execute as an independent
activity concurrent along with with other tasks and motion. When the task completes it will start again after the indicated period which is expressed in milliseconds. Note that any yields performed by the task are magnified by the period.
Each yield is extended in duration to the period value in milliseconds. If a period of zero is provided the task will be scheduled to run at the controller sample rate restarting as soo as it finishes on the next sample.
To avoid having every yield be the period in duration it is often more convenient to begin a task that has an explicit loop with a period delay inside the loop at a specific place.
Procedures can be run as concurrent tasks if they have no parameters.
Tasks cannot be object methods. Procedures with parameters or Object Methods can be called as tasks through a wrapper without parameters that provides the parameters to
the called procedure. Insure that such a wrapped procedure has re-entrant properties (operates only with local variables, not global variables) if multiple
wrappers call the same procedure.
The MAC Family supports 64 concurrent tasks in addition to concurrent motion which does not consume task resources
Escapes
If all of the available task slots are filled an attempt to start another task will result in an Unable To Begin Task Escape Code.
If the task number is specified that is less than 1 or greater than the MaxUserTasks constant inside the interpreter package a Parameter Out Of Range Escape Code error will occur.
MaxUserTasks has a value of 16 but can be adjusted if more tasks need to be invoked from the host.
Note that only 14 additional tasks can run at one time as two are used to sustain host communication.
Examples
ScheduleTask is most often used to maintain a low importance background task such as maintaining information in a display. The routine updates information on a number of windows controls:
This routine is started with this command:
Note that delays by Windows to perform requested operations are in addition to any period specification in the Schedule Task command. Activities that must be real-time in character cannot include Windows operations. In such cases it is best to have a resident task
that performs what is time critical and convey state, through variables, to a separate task that updates information in Windows.
Related Topics
Yield
Abort User Task
User Task Present
Schedule Task
TaskAddr