Example Listener
This sample illustrates the use of the TwinCAT 3 EventLogger in relation to messages and alarms. At the same time the reception of messages is shown in a second project.
Download the sample: https://github.com/Beckhoff/Tc3Eventlogger_Samples/tree/main/PLC/Tc3EventLogger_ListenerSample
Publisher project
Single BOOL variables are used as triggers in the Publisher project:
- 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 the JSON attribute in order to send it with both messages.
Listener project
The Listener project contains a function block, FB_Listener, which extends the FB_ListenerBase function block contained in the Tc3_EventLogger. The function block implements the functions for receiving the messages:
- 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.
- To initiate receiving of messages, an Execute method is implemented at the function block.
- The text of the last received message can be retrieved.
- The function block FB_ListenerTest uses the FB_Listener. In doing so it registers the event class to be received once. Another event class that exists is not received to demonstrate the filter functionality.
Requirements
Development environment | Target platform | PLC libraries to include |
---|---|---|
TwinCAT v3.1.4024.17 | PC or CX (x64, x86, ARM) | Tc3_EventLogger (>= v3.1.27.0) |