5.2. Event notification
The EC-Monitor provides event notification for a great number of events. These events are for example:
Bus state change
Link state change
Working counter errors
…
Any thread can register for these events to be notified. This is achieved by calling the API function
-
EC_T_DWORD emRegisterClient(EC_T_DWORD dwInstanceID, EC_PF_NOTIFY pfnNotify, EC_T_VOID *pCallerData, EC_T_REGISTERRESULTS *pRegResults)
An example implementation for processing notifications is contained in the class CEmNotification
of the EcMonitorDemo example, see Examples/Common/EcNotification.cpp
.. It implements the full framework to catch and process the EC-Monitor notifications.
The class is instantiated once and registered at the EC-Monitor with the call emRegisterClient()
. It contains the method ecatNotify()
as major entry point (or callback function) for every event notification.
There are two different ways events can be handled. The method of handling an event is primarily determined by the time required to handle the event and the processing context in which the event is to be handled.
5.2.1. Direct event notification handling
Minor events that take a very short time to process can be handled directly in the context in which they are recognized. A possible example of such an event is the detection of a false working counter (WKC).
The event handling is reduced to simply issuing a log message, which is not time critical. The event is handled directly within the context of the emExecJob()
function.
5.2.2. Postponed notification handling
Events that require more time-consuming processing cannot be handled directly in the context in which they are detected. The handling or processing of the event must be postponed. This is accomplished through a queue, which is also readily implemented using the CEmNotification
class.
By calling periodically CEmNotification::ProcessNotificationJobs()
, the application checks and handles all queued notifications.
Important
The call of CEmNotification::ProcessNotificationJobs()
shall NOT be executed in the context of EcMonitorJobTask()
. As the CPU time consumption may be high, this would have a high impact to the real-time behavior of the cyclic operation.