FB_ReadTc3Events

FB_ReadTc3Events 1:

Available from TwinCAT 3.1 Build 4026

FB_ReadTc3Events 2:

The function block enables the events of the TwinCAT 3 EventLogger to be displayed in the visualization element event table. FB_ReadTc3Events is contained in the library VisuElemEventTable, which is automatically added to the project when the event table is activated (see Configuration of the event table). To be able to use FB_ReadTc3Events, you must add a TargetVisualization or WebVisualization object to the project.

The function block FB_ReadTc3Events queries the occurring events of the TC3 EventLogger and makes them available in the form of the array aEvents. Internally, an implementation of FB_ListenerBase2 is used for this purpose. In order for the messages to be displayed in the event table, the array aEvents must be entered into its message data array property.

FB_ReadTc3Events 3: Inputs

VAR_INPUT
    bReadEvents         : BOOL;
    nLanguageID         : DINT;
    eDateAndTimeFormat  : E_DateAndTimeFormat;
    bClearTable         : BOOL;
    eMinSeverity        : TcEventSeverity;
END_VAR

Name

Type

Description

bReadEvents

BOOL

This input is used to enable the events to be read.

nLanguageID

DINT

Defines which translation of the event text is to be retrieved.

eDateAndTimeFormat

E_DateAndTimeFormat

Defines the format of the timestamps. The available options are:

  • de_DE – German notation: dd.MM.yyyy hh:mm:ss (24 h)
  • en_GB – British notation: dd/MM/yyyy hh:mm:ss (24 h)
  • en_US – American notation: MM/dd/yyyy hh:mm:ss (12 h)

bClearTable

BOOL

The event table is cleared via a positive edge at this input. Alarms that were not acknowledged or reset are not removed from the table.

eMinSeverity

TcEventSeverity

Only events whose severity is at least as high as the severity specified here are displayed in the event table.

FB_ReadTc3Events 4: Outputs

VAR_OUTPUT
    aEvents            : ARRAY [1..80] OF ST_ReadEventW;
    nNumberOfEvents    : UDINT;
    bError             : BOOL;
    hrErrorCode        : HRESULT;
END_VAR

Name

Type

Description

aEvents

ARRAY [1..80] OF ST_ReadEventW

The function block uses this array to make the evaluated events available. The array can store a maximum of 80 messages. If the number of events is large, older messages are overwritten.

nNumberOfEvents

UDINT

Indicates how many events were triggered.

bError

BOOL

This output is set if an error occurs when polling or processing the events.

hrErrorCode

HRESULT

Indicates the error code of the error that has occurred.

FB_ReadTc3Events 5: Methods

SetFilter

A previously configured filter of type FB_TcEventFilter (Link) can be passed to this method in order to specify which events are to be evaluated and displayed in the event table. The filtering applies from the time the "SetFilter" method is called and has no influence on events that have already occurred. The filtering can be removed by calling the method "SetFilter" with "NULL" as input parameter. Like in other cases, cancellation of the filtering applies to new events.

If the method is not called, the event table displays all events.

VAR_INPUT
    ipEventFilter    : I_TcEventFilter;
END_VAR

Name

Type

Description

ipEventFilter

I_TcEventFilter

Filter configuration that is used to specify which TwinCAT 3 EventLogger events are to be processed by the function block FB_ReadTc3Events.

FB_ReadTc3Events 6:

You can switch between different filter views by creating several instances of FB_ReadTc3Events and linking the event table with a reference to aEvents, which is assigned to the desired instance in each case.

Sample:

PROGRAM MAIN
VAR
    // FB_ReadTc3Events
    fbReadTc3Events     : FB_ReadTc3Events;
    bReadEvents         : BOOL := TRUE;
    nLanguage           : DINT := 1031;
    eDateAndTimeFormat  : Tc2_Utilities.E_DateAndTimeFormat := Tc2_Utilities.E_DateAndTimeFormat.de_DE;
    bClear              : BOOL;
    eSeverityMin        : TcEventSeverity;
    bError              : BOOL;
    hr                  : HRESULT;
    hrOccuredErrorCode  : HRESULT;

    // EventFilter
    bFilterInit         : BOOL;
    fbEventFilter       : FB_TcEventFilter;
END_VAR
// Configure EventFilter (filter possibility one, not necessary for use of FB_ReadTc3Events)
IF NOT bFilterInit THEN
    bFilterInit := TRUE;
    fbEventFilter.Clear();
    fbEventFilter.EventClass.EqualTo(TC_EVENTS.EventClass1.Message1.uuidEventClass).OR_OP().EventClass.EqualTo(TC_EVENTS.EventClass2.Alarm2.uuidEventClass).AND_OP().Severity.GreaterThan(0);
    hr := fbReadTc3Events.SetFilter(ipEventFilter := fbEventFilter);
    IF FAILED(hr) THEN
        hrOccuredErrorCode := hr;
    END_IF
END_IF

// Call fbReadTc3Events
fbReadTc3Events (
    bReadEvents         := bReadEvents,
    nLanguageID         := nLanguage,
    eDateAndTimeFormat  := eDateAndTimeFormat,
    bClearTable         := bClear,
    eMinSeverity        := eSeverityMin,          // Set event filter for severity via input (filter possibility two)
    nNumberOfEvents     => nEvents1,
    bError              => bError1,
    hrErrorCode         => );
IF fbReadTc3Events.bError THEN
    hrOccuredErrorCode  := fbReadTc3Events.hrErrorCode;
END_IF

Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT v3.1.4026

PC or CX (x86, x64, ARM)

VisuElemEventTable