(TcoTask : ITcoTask)
TcoTask is a block for managing chunks of logic in asynchronous execution. Task controls the run of a component's function (servo movement, piston movement, barcode reader trigger, etc.).
There are two key methods for managing the task:
Invokecall to fire the execution of the task (can be called fire&forget or cyclically)
Executemethod must be called cyclically (typically in the body of a FB). The method returns
TRUEwhen required the execution from a call of
Invokemethod until the task enters
FUNCTION_BLOCK BlocWithATask EXTENDS TcoCore.TcoObject VAR _counter : INT; _myTask : TcoCore.TcoTask(THIS^); END_IF // Body of a FB IF(_myTask.Exectute()) THEN _counter := _counter + 1; _myTask.DoneWhen(_counter = 100); END_IF;
The task executes upon the
Invoke method call.
Invoke fires the execution of
Execute logic upon the first call, and it does not need cyclical calling.
Invoke method returns
ITcoTaskStatus with the following members:
Busyindicates the execution started and is running.
Doneindicates the execution completed with success.
Errorindicates the execution terminated with a failure.
// Wait for the task to complete IF(_myTask.Invoke().Done) THEN ; // Do something END_IF; // ALTERNATIVELY _myTask.Invoke(); IF(_myTask.Done) THEN ; // Do something END_IF;
// Make sure that the task is executing IF(_myTask.Invoke().Busy) THEN ; // Do something END_IF;
// Check for task's error. IF(_myTask.Invoke().Error) THEN ; // Do something END_IF;
Restore is a function of
IRestoreable (implemented by TcoTask, TcoComponent...) It provides an initialization routine for the object; it recovers the object from any state into
After task completion, the state of the task will remain in
Restoremethod is called (task moves to
Invokemethod is not called for two or more cycles of its context (that usually means the same as PLC cycle); successive call of
Invokewill switch the task into
Readyand immediately to
If the task is part of complex coordination primitive, the transition between states will bring the task into a
Readystate if that primitive (StateController and derivatives) has this option enabled.
The task may finish in an
Error state. In that case, two recovery scenarios are possible:
Restoremethod is called (task goes to
Restorefrom on transition methods of a coordination block.