Support of the Tc3_Eventlogger
The TwinCAT 3 Database Server supports the TwinCAT 3 EventLogger (TwinCAT 3 Version 4022.20). This makes it possible to read out details of function block events via an interface. Further information on the EventLogger can be found in the TwinCAT 3 basic libraries.
All function blocks of the TwinCAT 3 Database Server support the interface of the Tc3 EventLogger. The interface Tc3_Eventlogger.I_TcMessage is used as the return value of the function blocks. In addition to the return value, the eTraceLevel property is available to determine the event weighting.
Properties
Name | Type | Access | Description |
---|---|---|---|
eTraceLevel | Get, Set | Specifies the weighting of the events. Only events with a weighting higher than this value are sent to the TwinCAT system. |
Sample:
As an example, the following weighting is specified for the function block FB_PLCDBWrite:
fbPLCDBWriteEvt.eTraceLevel := TcEventSeverity.Warning;
All events that represent at least a warning are now sent here. Events of the "Information" weighting are ignored in this case.
The Tc3_Database function blocks themselves have the output ipTcResult of data type Tc3_Eventlogger.I_TcMessage. All functions of this interface that are offered can be used.
In this sample, the function block is called first.
1: // Call Functionblock
IF fbPLCDBWriteEvt.WriteStruct(
hDBID:= 1,
sTableName:= 'myTable_Struct',
pRecord:= ADR(myRecord),
cbRecord:= SIZEOF(myRecord),
pColumnNames:= ADR(ColumnNames) ,
cbColumnNames:= SIZEOF(ColumnNames))
THEN
IF fbPLCDBWriteEvt.bError THEN
myTcMessage := fbPLCDBWriteEvt.ipTcResult
nState := 255;
ELSE
nState := 0;
END_IF
END_IF
If an error occurs, we now want to request the event text in the runtime environment. The RequestEventText method can be used for this purpose. Use nLangId =1031 to read the error code in German. This is one of the many functions of the Tc3_Eventlogger.I_TcMessage interface.
255://Request EventText
IF myTcMessage.RequestEventText(1031,
ADR(MyEventString),
SIZEOF(MyEventString))THEN
nState := 0;
END_IF