Open Core Interface - MLPI
MLPI-MotionLogicProgrammingInterface(mlpi4LabVIEW)  1.26.2
TaskLib
Collaboration diagram for TaskLib:

Modules

 Control Tasking
 
 Control Task Viewer
 
 Control Task Execution
 
 Version and Permission
 
 Structs, Types, ...
 

Detailed Description

Control and change the tasking and scheduling of the MLC/XLC system and the user application.

Using the task lib, it is possible to hook your task into the real-time task scheduler of the target system. Of course, this only makes sense if your program runs on the same target as the device you are connected to. Using the TaskLib when connecting via MLPI over Ethernet is possible, but the timing of the methods is non-deterministic. But when running with your app on the target, you can make sure that your task is one of the first tasks to get scheduled, when for example new data has arrived on the sercos bus. To do this, you have to increase the task priority of your task using mlpiTaskSetCurrentPriority and then you may want to wait for a given system event using mlpiTaskWaitForEvent.

Attention
Your task is scheduled with the same rights as every other (system) task in a fully native real-time environment! So special care is needed, when running your task at higher priority levels. Your task will block any task with a lower priority level as long as it is running. Programming an infinite loop will most likely look up your system (a system watchdog will stop your system). If you have never programmed a real-time system, then please have a look at the manual of your operating system and read about the mechanics of a real-time scheduler!

Here is some example code:

extern "C" int taskFunc(MLPIHANDLE connection)
{
// We use this example to make sure our task gets scheduled every time new data from the sercos has arrived.
// This way, we can have a code or an algorithm executed every sercos cycle. Much like having
// a cyclic PLC event task.
// Set task priority to high to make it one of the first tasks to run
// as soon as the event occurs.
if (MLPI_FAILED(result)) {
printf("\ncall of MLPI function failed with 0x%08x!", (unsigned)result);
return result;
}
unsigned long cycleCounter = 0;
bool bRunning = true;
do {
// wait for the next sercos cycle. Task will be set to state "pending"
// and not consume any cpu time.
if (MLPI_FAILED(result)) {
printf("\ncall of MLPI function failed with 0x%08x!", (unsigned)result);
break;
}
// you may want to do some cyclic calculation in here which
// depends on the sercos data, e.g. read input values, write outputs for
// next cycle, calculate new commanded axis positions, etc...
// note: do not block forever in here!
// Set bRunning to false if you want to exit the loop. In this example, we
// exit after 1000 loops.
cycleCounter++;
if (cycleCounter>1000)
bRunning = false;
}while (bRunning);
// set task priority back to background to not block any other tasks.
if (MLPI_FAILED(result)) {
printf("\ncall of MLPI function failed with 0x%08x!", (unsigned)result);
return result;
}
return MLPI_S_OK;
}

Here is another example which shows how to start our function on a VxWorks target. For more information about the usage of task on VxWorks, please have a look at the VxWorks Reference help regarding the taskLib functionality.

taskSpawn("ExampleTask", 100, VX_FP_TASK, 0x200000, (FUNCPTR)&taskFunc, connection, 0, 0, 0, 0, 0, 0, 0, 0, 0);
Note
The TaskLib functions trace their debug information mainly into the module MLPI_TASK_LIB and in addition into the module MLPI_BASE_MODULES. For further information, see also the detailed description of the library TraceLib and the notes about Using the Trace for debugging.