#3 Find or create a Codesys solution for: PlcTaskSystemInfo

v1.0
closed
aliazzz
None
2020-05-01
2019-05-04
aliazzz
No

Create/exchange the following datastucture with something more vanilla Codesys;

Each PLC contains an array of instances of this type. The name of the arrays is '_TaskInfo[]'.

The individual instances of this type can be accessed by using the index of the corresponding task as array index. The task index can be read via the function block GETCURTASKINDEX, which is provided by the Tc2_System library.

The corresponding namespace is 'TwinCAT_SystemInfoVarList'. This must be specified for use in a library, for example.

{attribute 'Namespace' := 'PLC'}
TYPE PlcTaskSystemInfo
STRUCT
     ObjId                   : OTCID;
     CycleTime               : UDINT;
     Priority                : UINT;
     AdsPort                 : UINT;
     CycleCount              : UDINT;
     DcTaskTime              : LINT;
     LastExecTime            : UDINT;
     FirstCycle              : BOOL; 
     CycleTimeExceeded       : BOOL; 
     InCallAfterOutputUpdate : BOOL; 
     RTViolation             : BOOL;

     TaskName                : STRING(63);
END_STRUCT
END_TYPE 

ObjId = Object ID of the task reference, from which the PLC program is called.
CycleTime = Set task cycle time in multiples of 100 ns
Priority = Set task priority
AdsPort = ADS port of the task
CycleCount = Cycle counter
DcTaskTime = Distributed clock system time. It remains constant for a task runtime.
LastExecTime = Cycle time required for the last cycle in multiples of 100 ns.
FirstCycle = During the first PLC task cycle, this variable has the value TRUE.
CycleTimeExceeded = This variable indicates whether the set task cycle time was exceeded.
InCallAfterOutputUpdate = This variable has the value TRUE if the origin of the current call is declared with the attribute 'TcCallAfterOutputUpdate'.
RTViolation = This variable has the value TRUE if the real-time limit is exceeded on a mixed core (Windows + real-time on one core). In this case the value TRUE refers to the core on which the corresponding task is running.
TaskName = Name of the task

Example:

VAR
     fbGetCurTaskIdx  : GETCURTASKINDEX;
     nCycleTime       : UDINT;
END_VAR

fbGetCurTaskIdx();
nCycleTime := _TaskInfo[fbGetCurTaskIdx.index].CycleTime;

Discussion

  • aliazzz

    aliazzz - 2019-05-04
    • summary: Create Codesys Solution for: PlcTaskSystemInfo --> Find or create a Codesys solution for: PlcTaskSystemInfo
     
  • aliazzz

    aliazzz - 2019-05-09

    Task Manager
    Using system library "CmpIecTask" Task information can be retrieved within a POU, so this data structure can be phased out/ replaced by vanilla Codesys using a system library "CmpIecTask" oriented solution.

     
  • aliazzz

    aliazzz - 2019-05-13
    • Owner: Anonymous --> aliazzz
    • Status: open --> closed
     

Log in to post a comment.