F_BA_LogMessage1

Internally, the function works with the function block FB_FormatString.
In the first run, a message string is generated from sLogText, which is assigned to tArg1. The assigned variable must be linked with the correct data type conversion to tArg1. 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_LogMessage1 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. In addition to the text "Message" the input variable sLogText of the function also contains a format specification "%s", which also displays the text "Appendix" of the variable sText1. Without the format specification " Appendix " would not appear.
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;
tArg1 : T_Arg;
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. |
tArg1 | T_Arg | Further message text, which is placed at the end. |
Requirements
Development environment | Required PLC library |
---|---|
TwinCAT 3.1 4024.35 | Tc3_BA2_Common from V2.1.20.0 |