Trace Messages
Trace messages can be used to log messages to the Output window. Any Function Block that inherits from the FB_BaseFB
in the SPT Base Types library will be able to use the Trace()
method. At its lowest level the Trace method parametrizes the FB_TcMessage
function block from the Tc3_EventLogger library and then calls its Send()
method to log the text to the Output window.
Note
An important feature of the implementation within the SPT library is to help prevent messages from being logged more than once. By default, the library Parameter ALLOW_DUPLICATE_SEQUENTIAL_MESSAGES
has an Initial value of FALSE.
When using the Trace method any string (literal or variable) can be passed to it, for example:
1 |
|
1 |
|
This will add the following entry in the output window:
1 |
|
Tip
It is required to set the ‘Show output from:’ drop down list to ‘TwinCAT’, otherwise the message will not be displayed.
The string will be displayed along with the Timestamp, the fully qualified name of the POU that calls the Trace method (but not the method name), and the PLC Cycle Number.
Danger
Care must be taken as the feature that does not allow for duplicate messages applies to a single instance of the Trace method. This means that if the Trace method is called from 2 methods of the same class, with a different string value then the duplication cannot be detected. It also means that if a child and a parent both use the Trace method with a different string value, then this also cannot be detected. Both use cases can cause duplicates to be logged cyclically.
The Trace message is good for logging status or confirming code during debug. Placing a Trace message within a state machine can provide confirmation that a state has been entered or completed. It can also be used to log the value of a variable at a specific condition (use TO_String).
1 |
|