Class TcoTask
Provides basic task execution. Task is started by calling the Invoke() method.
The Execute() method returns true, until the task is Done
.
To get the actual state of the task, Ready, Busy, Error and Done properties are available.
Inherited Members
Namespace: PlcDocu.TcoCore
Assembly: TcoCoreConnector.dll
Syntax
public abstract class TcoTask : TcoObject
Examples
Declaration part of the 'TcoTask' example.
(*
This example shows using the 'Tcotask' application. 'TcoTask' is the simplest
'TcoOpen' coordination primitive.
In general the body of the task could be devided into the three section:
1.) Action
2.) Termination condition for the expected behavior.
3.) Termination condition for the non-expected behavior.
The body of the 'Tcotask' needs to be called cyclically. The 'Tcotask' could be then
invoked from 'outside'. The task of this 'Tcotask' is to ask for the favor
(in the name of the 'TcoContext' in this example Don Corleone) and offer the return favor.
Task could end up the expected way in the 'DONE' state if the requested person grant
the favor or it could end up in the 'ERROR' state if the requested person refuses to grant
the favor. Each task could be invoked only from the 'READY' state. So if the task enters
the 'ERROR' state, it cannot be invoked again and has to be restored before. Anyway in this
example this task is never restored and invoked again as Don Corleone never asks for the
next favor if the first one was refused.
*)
FUNCTION_BLOCK AskForTheFavor_Task EXTENDS TcoCore.TcoTask
VAR_INPUT
(*
'Parameters' of this task are assigned in this example from 'outside' from the
'upper level' of the hierarchy, where Invoke() method is triggered.
*)
_Person_Requested : REFERENCE TO Person_Object;
_RequestedFavor : STRING;
_ReturnFavor : STRING;
END_VAR
Implementation part of the 'TcoTask' example.
// THIS part needs to be called cyclically.
IF Execute() THEN
// First section: Action.
// Meet the right person and interpret the requirements so as a possible return favor.
_Person_Requested.RequestForTheFavor(_RequestedFavor,_ReturnFavor);
// Let the person requested to think carefully about the proposition.
_Person_Requested.ThinkCarefully();
// Second section: Termination condition for the expected behavior.
// In the case that the requested person is "smart" and "show the respect" to the
// 'TcoContext', task finishes in the 'DONE' state and process of the granted the
// return favor should be started.
DoneWhen(_Person_Requested.FavorIsGranted());
// Third section: Termination condition for the non-expected behavior.
// In the case that the requested person is so self-confident and refuse to grant
// the favor, task finishes in the 'ERROR' state and automatically the OnTaskError()
// method is triggered. In this method normally the value of the ReturnFavor is
// drammatically decreased OR changed to 'Nothing'. Anyway the requested person still
// have the possibility to grant the favor but under different condition, as he
// "had to do it the hard way".
ThrowWhen(_Person_Requested.FavorIsRefused());
END_IF
Example of the invoking this example 'TcoTask' instance 'outside' of the instance and wait if it ends-up in 'DONE' state or in 'ERROR' state.
//Starting the execution of the 'TcoTask' instance extended by input parameters from 'outside' of the instance.
Thomas.AskForTheFavor(Jack_Woltz,'Grant movie role to Johny Fontane.','No future problems with unions.').Invoke();
// Checking from the 'outside' of the instance, if the task has already finished in expected way.
_FirstOfferAccepted := Thomas._AskForTheFavor.Done;
// Checking from the 'outside' of the instance, if the task has finished in non-expected way.
_FirstOfferRefused := Thomas._AskForTheFavor.Error;
Constructors
| Improve this Doc View SourceTcoTask()
Prevents creating instance of this class via public constructor
Declaration
public TcoTask()
Fields
| Improve this Doc View Source_abortRequest
Use to abort the executing task and set this instance back to the Ready state. The value is than set to FALSE.
Declaration
public object _abortRequest
Field Value
Type | Description |
---|---|
System.Object |
_elapsedTime
Declaration
public object _elapsedTime
Field Value
Type | Description |
---|---|
System.Object |
_enabled
Use to determine if the task execution is enabled for example from the HMI application. This value is read only, to modify it use the property Enabled
Declaration
public object _enabled
Field Value
Type | Description |
---|---|
System.Object |
_invokeRequest
Use to start the execution of the task from Ready state or from Done state by performing the rising edge.
Analogously to the xExecute signal of the PLCopen motion function blocks.
Declaration
public object _invokeRequest
Field Value
Type | Description |
---|---|
System.Object |
_isServiceable
Indicates whether the task is in serviceable state. The default state 'serviceable' that means that the task
can be invoked from the higher-level application. The serviceable state is cancelled when the immediate parent is ITcoServiceable
and at the same time the parent is not in servicebable state. TcoComponent
is serviceable, in order for the component's task to be
invokable from higher-level application component must call Service
method to induce the component into serviceable state.
Declaration
public object _isServiceable
Field Value
Type | Description |
---|---|
System.Object |
_restoreRequest
Use to restore this instance to the Ready state. The value is than set to FALSE.
Declaration
public object _restoreRequest
Field Value
Type | Description |
---|---|
System.Object |
_taskState
Declaration
public short _taskState
Field Value
Type | Description |
---|---|
System.Int16 |
Properties
| Improve this Doc View SourceAutoRestorable
Gets whether this instance is auto restorable. This is depends on the parent's settings; the value of this property is given by the parent of this object.
This value is assigned after download by calling the implicit method FB_init()
of the parent object and cannot be changed during runtime.
The AutoRestorable
property of this objects is retrieved from the EnableAutoRestore
property of the parent object.
This is done by calling the CheckIfAutoRestoreEnabledByParent()
method inside the implicit method FB_init()
after download.
If this instance is the auto restorable it will call the Restore() method if:
1.) The Invoke() method has not been called for one or more cycles and starts to be called again.
2.) Parent object of this instance changes its state.
See also
Declaration
[IgnoreReflection]
public dynamic AutoRestorable { get; }
Property Value
Type | Description |
---|---|
System.Object | Plc type BOOL; Twin type: Vortex.Connector.ValueTypes.OnlinerBool |
Busy
Gets whether the task is executing.
Declaration
[IgnoreReflection]
public dynamic Busy { get; }
Property Value
Type | Description |
---|---|
System.Object | Plc type BOOL; Twin type: Vortex.Connector.ValueTypes.OnlinerBool |
Context
Gets the context of this object.
This context is given by declaration, its value is assigned after download by calling the implicit method FB_init()
and cannot be changed during runtime.
Declaration
[IgnoreReflection]
public dynamic Context { get; }
Property Value
Type | Description |
---|---|
System.Object | Plc type ITcoContext; Twin type: |
Done
Gets whether the task has succesfully completed the execution and did not enter into the Error state.
Declaration
[IgnoreReflection]
public dynamic Done { get; }
Property Value
Type | Description |
---|---|
System.Object | Plc type BOOL; Twin type: Vortex.Connector.ValueTypes.OnlinerBool |
ElapsedTime
Gets the elapsed time of the execution of this task.
Uses `TIME` type. It might be not sutable for tasks running longer than 49 days.
important
Declaration
[IgnoreReflection]
public dynamic ElapsedTime { get; }
Property Value
Type | Description |
---|---|
System.Object | Plc type TIME; Twin type: Vortex.Connector.ValueTypes.OnlinerTime |
Enabled
Gets whether the task execution is enabled.
The task can start with Invoke() method call only when this property si TRUE.
If the task is Busy
and this property transitions to FALSE
, the task stops execution and enters Error
state.
Declaration
[IgnoreReflection]
public dynamic Enabled { get; }
Property Value
Type | Description |
---|---|
System.Object | Plc type BOOL; Twin type: Vortex.Connector.ValueTypes.OnlinerBool |
Error
Returns true if the task has is in error state. To be able to start the the task again, Restore() method needs to be called before restarting it again calling Invoke() method.
Declaration
[IgnoreReflection]
public dynamic Error { get; }
Property Value
Type | Description |
---|---|
System.Object | Plc type BOOL; Twin type: Vortex.Connector.ValueTypes.OnlinerBool |
Identity
Gets identity of this TcoTask().
This value is assigned after download by calling the implicit method FB_init()
and cannot be changed during runtime.
This variable is used in the higher level applications.
Declaration
[IgnoreReflection]
public dynamic Identity { get; }
Property Value
Type | Description |
---|---|
System.Object | Plc type ULINT; Twin type: Vortex.Connector.ValueTypes.OnlinerULInt |
Ready
Gets whether the task is ready to be started (Tasks start by calling the Invoke() method).
Declaration
[IgnoreReflection]
public dynamic Ready { get; }
Property Value
Type | Description |
---|---|
System.Object | Plc type BOOL; Twin type: Vortex.Connector.ValueTypes.OnlinerBool |
State
Gets the actual state of this instance.
See
Declaration
[IgnoreReflection]
public dynamic State { get; }
Property Value
Type | Description |
---|---|
System.Object | Plc type eTaskState; Twin type: |
Methods
| Improve this Doc View SourceAbort()
Aborts the execution of this task and restores the ready state.
Declaration
[IgnoreReflection]
public void Abort()
AutoRestore()
Private method called each time that the Execute() method is called. If this instance is auto restorable, this method ensures calling the Restore() method if:
1.) Parent object of this instance changes its state in this Plc cycle.
2.) Parent object of this instance changes its state no mather when and this instance has not yet process this change.
3.) The Invoke() method has not been called for one or more cycles and starts to be called again.
See also AutoRestorable
See also
Declaration
[IgnoreReflection]
void AutoRestore()
CheckIfAutoRestoreEnabledByParent()
Declaration
[IgnoreReflection]
void CheckIfAutoRestoreEnabledByParent()
CheckIfCalledCyclically()
Private method called inside the Execute() method checking the cyclicall calling of this method. If this instance is auto restorable, this method ensures calling the Restore() method if the Execute() method has not been called for one or more cycles and starts to be called again.
See also AutoRestorable
See also
Declaration
[IgnoreReflection]
void CheckIfCalledCyclically()
DoneWhen(Object)
Completes the execution of this task when inCondition
is true; the task transitions into Done
state.
Declaration
[IgnoreReflection]
public void DoneWhen(dynamic inCondition)
Parameters
Type | Name | Description |
---|---|---|
System.Object | inCondition | Plc type : BOOL [VAR_INPUT]; Twin type : Vortex.Connector.ValueTypes.OnlinerBool
|
Execute()
Returns true if the task is Busy, otherwise false. This method needs to be called cyclically.
Declaration
[IgnoreReflection]
public dynamic Execute()
Returns
Type | Description |
---|---|
System.Object | Plc type BOOL; Twin type: Vortex.Connector.ValueTypes.OnlinerBool |
Invoke()
Use to start the execution of the task. The starting is possible from Ready state.
Moreover it is also possible to start the task again from Done state by performing the '''rising edge''' of the calling of the Invoke() method.
Analogously to the xExecute signal of the PLCopen motion function blocks.
Declaration
[IgnoreReflection]
public dynamic Invoke()
Returns
Type | Description |
---|---|
System.Object | Plc type ITcoTaskStatus; Twin type: |
OnAbort()
Executes when task is aborted.
Declaration
[IgnoreReflection]
protected void OnAbort()
OnDone()
Executes when task reaches the Done
state .
Declaration
[IgnoreReflection]
protected void OnDone()
OnError()
Executes when task reaches the Error
state.
Do not confuse with WhileError(), that is called cyclically until '''Error''' state is left.
Declaration
[IgnoreReflection]
protected void OnError()
Restore()
Restores this instance to the Ready state. Can be called explicitly or from within one of the restore mechanisms.
See also AutoRestorable
Declaration
[IgnoreReflection]
public dynamic Restore()
Returns
Type | Description |
---|---|
System.Object | Plc type ITcoRestorable; Twin type: |
ThrowWhen(Object)
When called with inCondition
TRUE
causes transition of the task into the Error
state.
Declaration
[IgnoreReflection]
public void ThrowWhen(dynamic inCondition)
Parameters
Type | Name | Description |
---|---|---|
System.Object | inCondition | Plc type : BOOL [VAR_INPUT]; Twin type : Vortex.Connector.ValueTypes.OnlinerBool
|
WhileError()
Executes until task is in Error
state .
Do not confuse with OnError(), that is called just ones when '''Error''' state is entered.
Declaration
[IgnoreReflection]
protected void WhileError()