Example Listener
This sample illustrates the use of the TwinCAT 3 EventLogger in relation to messages and alarms.
It consists of a module that can send a message and an alarm, and a module that receives these messages.
Download the sample: https://github.com/Beckhoff/Tc3Eventlogger_Samples/tree/main/C%2B%2B(RT)/Tc3EventLogger_CppListener_Sample
Publisher module
Single BOOL variables are used in the Publisher module as triggers on the input data area:
- bSendMessage to send a message
- bRaiseAlarm to set an alarm
- bClearAlarm to cancel an alarm
- bConfirmAlarm to confirm an alarm
In addition there is an option to set and to remove the JSON attribute in order to send it with both messages.
Listener module
The Listener module implements both the ITCMessageListener and the ITcAlarmListener interface. The methods specified as a result of this are called by the EventLogger as callback.
- OnMessageSent: when a message has been sent the EventLogger will call this method as a callback. The method counts the number of messages.
- OnAlarmRaised/OnAlarmCleared/OnAlarmConfirmed: if the alarm changes its state the EventLogger will call this method as a callback. The methods count the number of state changes.
The Listener module thereby registers itself with the EventLogger for the corresponding event classes on starting in the method SetObjStateSO().