F_BA_LogMessage

Internally, the function F_BA_LogMessage works with the function block FB_FormatString.
In the first run, a message string is generated from sLogText. The text sLogText needs a valid format specification in addition to the message text.
The resulting text is preceded by a text argument in square brackets in the second run of FB_FormatString.
Sample

The F_BA_LogMessage function is run in ten consecutive cycles, then no more. The log type is ADSLOG_MSGTYPE_ERROR, which means that the message output is of the error message type. The variable sLogCode is assigned the control variable i, which appears in the text in square brackets. The input variable sLogText of the function contains the text "Message".
Output

The generated code is used to identify a specific location in the source code. The sample shown above serves to illustrate how this function works. Basically, a distinctive abbreviation (e.g. "IO50" if a message is issued within the method InitObject in line 50) should be explicitly specified for the generation of the log messages.
This will display an error at runtime and the shortcut "Ctrl+F" will reach the erroneous location.
Syntax
FUNCTION F_BA_LogMessage
VAR_INPUT
nLogType : DWORD := ADSLOG_MSGTYPE_ERROR;
sLogCode : STRING := '';
sLogText : T_MaxString;
END_VAR
Inputs
Name | Type | Description |
---|---|---|
nLogType | DWORD | Log type, which can be set as a mask. The message is then output depending on the setting of this mask. The mask for ADSLOG_MSGTYPE_LOG is set internally as well. |
sLogCode | STRING | An argument in textual form that precedes the message. |
sLogText | T_MaxString | Message as text |
Requirements
Development environment | Required PLC library |
---|---|
TwinCAT 3.1 4024.35 | Tc3_BA2_Common from V2.1.20.0 |