Arguments
The texts of the events can be individualized by programming with "arguments".
A marking with the notation {n}
is used for this during the description of the events in the TMC editor, where n
is an ascending number starting from 0.
Up to 128 arguments with a maximum size of 1024 bytes can be used at one event.
In the TMC editor, for example, such a Display Text is used for an event:
This can then be used in the source code, as explained below.
PLC
Arguments can be handled in the PLC as follows:
fbMsg : FB_TcMessage;
IF NOT fbMsg.EqualsToEventEntryEx(stOther:=TC_EVENTS.CalculationEventClass.DivisionByZero) THEN
hr := fbMsg.CreateEx(TC_EVENTS.CalculationEventClass.DivisionByZero, 0 (*fbSource*) );
END_IF
fbMsg.ipArguments.Clear().AddLReal(fDividend); //set Argument
The arguments must thereby be defined after Create()/CreateEx(), but before Send().
Several arguments can be specified in concatenated form.
fbMsg.ipArguments.Clear().AddLReal(fDividend).AddLReal(fDivisor);
In this case fDividend
is set in place of {0}
and fDivisor
in place of {1}
.
C++
Arguments can be handled in the C++ as follows:
TcArgs tcArgs(m_spMessage);
tcArgs->Clear();
tcArgs.AddArgument(m_dividend);
The arguments must thereby be defined after CreateMessage()/CreateAlarm(), but before Send().
For this, TcEventLoggerTemplate.h
must be included in <ProjectName>Interfaces.h
.
#include"TcRouterInterfaces.h"
#include"TcEventLoggerTemplates.h"
///<AutoGeneratedContent id="Interfaces">
///</AutoGeneratedContent>
Output
The output is accordingly:
This notation can also be used as text within the translations.
If more arguments are sent than provided by corresponding placeholders, they are appended to the event text in parentheses. This behavior can be suppressed by setting the "HideNeedlessArguments" option for the event class, as described here.
Formatting
The output of the arguments can also be formatted. To do this the syntax {n,<Format>}
is used accordingly in the TMC editor:
The following formats are available:
Type | Format | Description |
---|---|---|
Numerical value | d / D | Decimal representation |
| e / E | Exponential representation |
| x / X | Hexadecimal representation |
| f / F | Fixed point |
Note that, for example, a REAL cannot be represented as "d" or "x" etc.
Additional notes regarding arguments in message texts
- In addition, the syntax
{eventID}
(for the Event ID) and{eventclass}
(for the Guid of the event class) are available to output the corresponding information as part of the text. - If strings are used as arguments
AddString()
, they are inserted as arguments in the message text. This string cannot be translated by the TwinCAT 3 EventLogger. If an argument is to be translated,.AddEventReferenceEx()
can be used for this purpose. Here, the message text is inserted in the corresponding translation. The Example Listener shows the usage.