Class TcoContext
Root construction container, provides context information for TcoObjects
declared within its scope.
This function block is abstract
and cannot be instantiated.
Use Run() to run this context, Run
method must be called only once per PLC Task cycle.
Several 'TcoContext' instances can be declared and called inside one TwinCAT PlcTask, but only once per PLC cycle.
The instance should not be accessed from several Twincat PlcTasks.
Default implemenation of the 'TcoContext' allows its child members access properties StartCycleCount
and EndCycleCount, messenger settings, rtc and other information related to the context of the running logic.
tip
A TcoContext
can contain objects, components and PLC logic of one independent station of the machine,
while the another one can cover the same for another station.
tip
TwinCAT PlcTask and TcoTask() refer to two different concepts.
Inherited Members
Namespace: PlcDocu.TcoCore
Assembly: TcoCoreConnector.dll
Syntax
public abstract class TcoContext
Examples
Declaration part of the 'TcoContext' example.
(*
THIS EXAMPLE AIMS TO EXPLAIN WHAT CONTEXT AND IDENITY ARE IN A 'TcoOpen' APPLICATION.
SEE Main() method of this block.
*)
FUNCTION_BLOCK VitoCorleone_Context EXTENDS TcoCore.TcoContext
VAR
(*
Each context member object has it 'context' and assigned when instantiated (at birth)
This is typically done by instantiating the objects with FB_init(ITcoObject) as follows
These are Don Corleone's children. When you look inside definitions you' find
Don Corleone's grand-childrend (whole family shares the same context).
*)
_santino : Santino_Object(THIS^);
_thomas : Thomas_Object(THIS^);
_frederico : Frederico_Object(THIS^);
_michael : Michael_Object(THIS^);
_costanzia : Constanzia_Object(THIS^);
END_VAR
VAR
_donCorleoneContext : ITcoContext;
_isSameContext : BOOL;
_donCorleoneIdentity : ULINT;
_isDifferentIndentity : BOOL;
END_VAR
Implementation part of the 'TcoContext' example.
(*
CONTEXT vs IDENTITY
*)
// In Corleone family they all share the same context that is that of Don Vito Corleone
// Here is the tree of family Corleone
// https://godfather.fandom.com/wiki/Corleone_family
_donCorleoneContext := THIS^.Context;
_isSameContext :=
// Santino
_donCorleoneContext = THIS^._santino.Context
// Santino's kids
AND (THIS^._santino.Context = THIS^._santino._francesca.Context
AND THIS^._santino.Context = THIS^._santino._frank.Context
AND THIS^._santino.Context = THIS^._santino._kathryn.Context
AND THIS^._santino.Context = THIS^._santino._santino.Context)
// Thomas
AND THIS^._santino.Context = THIS^._thomas.Context
// Thomas' kids
AND (THIS^._thomas.Context = THIS^._thomas._andrew.Context
AND THIS^._thomas.Context = THIS^._thomas._christina.Context
AND THIS^._thomas.Context = THIS^._thomas._frank.Context
AND THIS^._thomas.Context = THIS^._thomas._gianna.Context)
// Frederico
AND THIS^._thomas.Context = THIS^._frederico.Context
// Frederico's kids
AND (THIS^._frederico.Context = THIS^._frederico._fredo.Context)
// Michael
AND THIS^._frederico.Context = THIS^._michael.Context
// Michael's kids
AND (THIS^._michael.Context = THIS^._michael._anthony.Context
AND THIS^._michael.Context = THIS^._michael._mary.Context)
// Constanzia
AND THIS^._michael.Context = THIS^._costanzia.Context
// Constanzia's kids
AND (THIS^._costanzia.Context = THIS^._costanzia._michael.Context
AND THIS^._costanzia.Context = THIS^._costanzia._victor.Context);
// However each member of the family has different personal identity and that might
// be source of trouble
_donCorleoneIdentity := THIS^.Identity;
_isDifferentIndentity :=
// Santino
_donCorleoneIdentity <> THIS^._santino.Identity
// Santino's kids
AND (THIS^._santino.Identity <> THIS^._santino._francesca.Identity
AND THIS^._santino.Identity <> THIS^._santino._frank.Identity
AND THIS^._santino.Identity <> THIS^._santino._kathryn.Identity
AND THIS^._santino.Identity <> THIS^._santino._santino.Identity)
// Thomas
AND THIS^._santino.Identity <> THIS^._thomas.Identity
// Thomas' kids
AND (THIS^._thomas.Identity <> THIS^._thomas._andrew.Identity
AND THIS^._thomas.Identity <> THIS^._thomas._christina.Identity
AND THIS^._thomas.Identity <> THIS^._thomas._frank.Identity
AND THIS^._thomas.Identity <> THIS^._thomas._gianna.Identity)
// Frederico
AND THIS^._thomas.Identity <> THIS^._frederico.Identity
// Frederico's kids
AND (THIS^._frederico.Identity <> THIS^._frederico._fredo.Identity)
// Michael
AND THIS^._frederico.Identity <> THIS^._michael.Identity
// Michael's kids
AND (THIS^._michael.Identity <> THIS^._michael._anthony.Identity
AND THIS^._michael.Identity <> THIS^._michael._mary.Identity)
// Constanzia
AND THIS^._michael.Identity <> THIS^._costanzia.Identity
// Constanzia's kids
AND (THIS^._costanzia.Identity <> THIS^._costanzia._michael.Identity
AND THIS^._costanzia.Identity <> THIS^._costanzia._victor.Identity);
// Once the context is asigned (at birth [instantiated]) it cannot be changed,
// an attempt to change the context will result in vendetta.
Constructors
| Improve this Doc View SourceTcoContext()
Prevents creating instance of this class via public constructor
Declaration
public TcoContext()
Fields
| Improve this Doc View Source_endCycleCount
Declaration
public object _endCycleCount
Field Value
Type | Description |
---|---|
System.Object |
_Identity
Identity of this TcoContext
.
This variable is used in the higher level applications,
it allows to identify the context in SCADA like applications.
Declaration
public object _Identity
Field Value
Type | Description |
---|---|
System.Object |
_logger
Declaration
public TcoLogger _logger
Field Value
Type | Description |
---|---|
TcoLogger |
_messagingLevel
Declaration
public short _messagingLevel
Field Value
Type | Description |
---|---|
System.Int16 |
_rtc
Declaration
public TcoRtc _rtc
Field Value
Type | Description |
---|---|
TcoRtc |
_settings
Declaration
public TcoContextEnvironment _settings
Field Value
Type | Description |
---|---|
TcoContextEnvironment |
_startCycleCount
Declaration
public object _startCycleCount
Field Value
Type | Description |
---|---|
System.Object |
_timeSychnMessenger
Declaration
public TcoMessenger _timeSychnMessenger
Field Value
Type | Description |
---|---|
TcoMessenger |
Properties
| Improve this Doc View SourceContext
Returns reference to this instance of the TcoContext().
Declaration
[IgnoreReflection]
public dynamic Context { get; }
Property Value
Type | Description |
---|---|
System.Object | Plc type ITcoContext; Twin type: |
EndCycleCount
Gets the value of the counter incrememented by '1' at the end of each execution of this TcoContext().
Declaration
[IgnoreReflection]
public dynamic EndCycleCount { get; }
Property Value
Type | Description |
---|---|
System.Object | Plc type ULINT; Twin type: Vortex.Connector.ValueTypes.OnlinerULInt |
Identity
Returns the identity of this TcoContext(). This value is assigned when instantiated and cannot be changed at runtime. This member 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 |
Logger
Gets logger for this context.
Declaration
[IgnoreReflection]
public dynamic Logger { get; }
Property Value
Type | Description |
---|---|
System.Object | Plc type ITcoLogger; Twin type: |
StartCycleCount
Gets number of executions of this context. Value of this property is incremented by '1' at the beginning of the TcoContext().
Declaration
[IgnoreReflection]
public dynamic StartCycleCount { get; }
Property Value
Type | Description |
---|---|
System.Object | Plc type ULINT; Twin type: Vortex.Connector.ValueTypes.OnlinerULInt |
Methods
| Improve this Doc View SourceClose()
This method is called implicitly at the entry point of this context (Run()).
Do not call this method explicitly!
important
Declaration
[IgnoreReflection]
void Close()
Main()
Main method of the TcoContext. This is the entry point of any control logic that belongs to this context.
The call of this method is ensured by calling the InstanceName.Run()
method, and it must not be called explicitly.
This method is abstract, and it must be overridden in derived block.
Declaration
[IgnoreReflection]
protected void Main()
OnEntry()
Called on entry into context. When overridden in derived class allows to execute an arbitrary logic prior to opening the context cycle.
The method executes prior to opening the context. The context might not be properly initialized on first call.
Any information contained in the context at this point are from the last execution.
important
Declaration
[IgnoreReflection]
protected void OnEntry()
OnExit()
Called upon exit from the context. When overridden in derived class allows to execute an arbitrary logic after closing the context cycle.
Declaration
[IgnoreReflection]
protected void OnExit()
Open()
This method is called implicitly at the entry point of this context (Run()).
Do not call this method explicitly.
important
Declaration
[IgnoreReflection]
void Open()
RtcSynchronize(Object, Object, Object)
Syncronizes the Real Time Clock (RTC) from given source.
There is single RTC source for entire application. All context share the same RTC source.
important
Declaration
[IgnoreReflection]
public dynamic RtcSynchronize(dynamic inDoSynch, dynamic inSyncAmsId, dynamic inSyncPeriod)
Parameters
Type | Name | Description |
---|---|---|
System.Object | inDoSynch | Plc type : BOOL [VAR_INPUT]; Twin type : Vortex.Connector.ValueTypes.OnlinerBool
|
System.Object | inSyncAmsId | Plc type : STRING [VAR_INPUT]; Twin type : Vortex.Connector.ValueTypes.OnlinerString
|
System.Object | inSyncPeriod | Plc type : UINT [VAR_INPUT]; Twin type : Vortex.Connector.ValueTypes.OnlinerUInt
|
Returns
Type | Description |
---|---|
System.Object | Plc type TcoContext; Twin type: TcoContext |
Run()
This method executes of this context. It provided correct order of execution order of inner methods. Any logic of this context must be called within Main()
method. This method is final, so it cannot be overriden. The InstanceName.Run()
needs to be called cyclically.
Declaration
[IgnoreReflection]
public void Run()