# Generic notification interface One of the parameters the client has to set when registering with the EtherCAT® MainDevice is a generic notification callback function ( `emNotify()`). The MainDevice calls this function every time an event (for example an error event) occurs about which the client has to be informed. Within this callback function the client must not call any active EtherCAT® functions which finally would lead to send EtherCAT® commands (e.g. initiation of mailbox transfers, starting/stopping the MainDevice, sending raw commands). In such cases the behavior is undefined. This callback function is usually called in the context of the EtherCAT® MainDevice timer thread or the EtherCAT® Real-time Ethernet Driver receiver thread. It may also be called within the context of a user thread (when calling an EtherCAT® MainDevice function). To avoid dead-lock situations the notification callback handler may not use mutex semaphores. As the whole EtherCAT® operation is blocked while calling this function the error handling must not use much CPU time or even call operating system functions that may block. Usually the error handling will be done in a separate application thread. ## Notification callback: emNotify When a client registers with the EtherCAT® MainDevice the client has to determine a generic notification callback function. The MainDevice calls this function every time an event (for example an error event or operational state change event) occurs about which the client has to be informed. Within this callback function the client must not call any active EtherCAT® functions which finally would lead to sending EtherCAT® commands (e.g. initiation of mailbox transfers, starting/stopping the MainDevice, sending raw commands). In such cases the behavior is undefined. Only EtherCAT® functions which are explicitly marked to be callable within `emNotify()` may be called. A further important rule exists due to the fact that this callback function is usually called in the context of the EtherCAT® MainDevice timer thread. As the whole EtherCAT® operation is blocked while calling this function the notification handler must not use much CPU time or even call operating system functions that may block. Time consuming operations should be executed in separate application threads. ### typedef [EC_T_DWORD](toc_api.html.md#_CPPv410EC_T_DWORD) (\*[EC_PF_NOTIFY](api_general_functions.html.md#_CPPv412EC_PF_NOTIFY))([EC_T_DWORD](toc_api.html.md#_CPPv410EC_T_DWORD) dwCode, [EC_T_NOTIFYPARMS](#_CPPv416EC_T_NOTIFYPARMS) \*pParms) ### struct EC_T_NOTIFYPARMS Data structure filled with detailed information about the according notification. ### Public Members ### EC_T_VOID \*pCallerData [in] Client depending caller data parameter. This pointer is one of the parameters when the client registers. ### [EC_T_BYTE](toc_api.html.md#_CPPv49EC_T_BYTE) \*pbyInBuf [in] Notification input parameters ### [EC_T_DWORD](toc_api.html.md#_CPPv410EC_T_DWORD) dwInBufSize [in] Size of notification input parameters in bytes ### [EC_T_BYTE](toc_api.html.md#_CPPv49EC_T_BYTE) \*pbyOutBuf [out] Buffer for notification output (result) ### [EC_T_DWORD](toc_api.html.md#_CPPv410EC_T_DWORD) dwOutBufSize [in] Size of buffer at pbyOutBuf in bytes ### [EC_T_DWORD](toc_api.html.md#_CPPv410EC_T_DWORD) \*pdwNumOutData [out] Amount of bytes written to pbyOutBuf by notification. EC_NULL: amount not set by notification. ## emNotify - EC_NOTIFY_STATECHANGED Notification about a change in the MainDevice’s operational state. This notification is enabled by default. **emNotify - EC_NOTIFY_STATECHANGED** : **Parameter** : * `pbyInBuf`: [in] Pointer to data of type EC_T_STATECHANGE which contains the old and the new MainDevice operational state * `dwInBufSize`: [in] Size of the input buffer provided at pbyInBuf in bytes * `pbyOutBuf`: [out] Should be set to EC_NULL * `dwOutBufSize`: [in] Should be set to 0 * `pdwNumOutData`: [out] Should be set to EC_NULL ### struct EC_T_STATECHANGE ### Public Members ### [EC_T_STATE](api_general_functions.html.md#_CPPv410EC_T_STATE) oldState Old operational state ### [EC_T_STATE](api_general_functions.html.md#_CPPv410EC_T_STATE) newState New operational state #### SEE ALSO [emIoCtl - EC_IOCTL_SET_NOTIFICATION_ENABLED](#emioctl-ec-ioctl-set-notification-enabled) for how to control the deactivation ## emNotify - EC_NOTIFY_XXXX Notification about an error. **emNotify - EC_NOTIFY_XXXX** : **Parameter** : * `pbyInBuf`: [in] Pointer to data of type EC_T_ERROR_NOTIFICATION_DESC * `dwInBufSize`: [in] Size of the input buffer provided at pbyInBuf in bytes * `pbyOutBuf`: [out] Should be set to EC_NULL * `dwOutBufSize`: [in] Should be set to 0 * `pdwNumOutData`: [out] Should be set to EC_NULL #### SEE ALSO [Diagnosis, error detection, error notifications](api_diagnosis.html.md#diagnosis-error-detection-error-notifications) ## Feature Pack MainDevice Redundancy Notifcations #### SEE ALSO Feature Pack “MainDevice Redundancy” ## emNotifyApp By calling this function the generic notification callback function setup by [`emRegisterClient()`](api_general_functions.html.md#_CPPv416emRegisterClient10EC_T_DWORD12EC_PF_NOTIFYP9EC_T_VOIDP20EC_T_REGISTERRESULTS) is called for all clients including RAS. ### static [EC_T_DWORD](toc_api.html.md#_CPPv410EC_T_DWORD) ecatNotifyApp([EC_T_DWORD](toc_api.html.md#_CPPv410EC_T_DWORD) dwCode, [EC_T_NOTIFYPARMS](#_CPPv416EC_T_NOTIFYPARMS) \*pParms) ### [EC_T_DWORD](toc_api.html.md#_CPPv410EC_T_DWORD) emNotifyApp([EC_T_DWORD](toc_api.html.md#_CPPv410EC_T_DWORD) dwInstanceID, [EC_T_DWORD](toc_api.html.md#_CPPv410EC_T_DWORD) dwCode, [EC_T_NOTIFYPARMS](#_CPPv416EC_T_NOTIFYPARMS) \*pParms) Calls the notification callback functions of all registered clients. #### NOTE EC_E_ERROR and EC_E_INVALIDPARM from registered clients’ callback functions are ignored. * **Parameters:** * **dwInstanceID** – [in] Instance ID (Multiple EtherCAT Network Support) * **dwCode** – [in] Application specific notification code. dwCode must be <= EC_NOTIFY_APP_MAX_CODE. The callback functions get “EC_NOTIFY_APP | dwCode” as parameter. * **pParms** – [in] Parameter to all callback functions. Note: Output parameters are not transferred from RAS client to RAS server. * **Returns:** [EC_E_ERROR](error-codes_generic.html.md#d3/d2f/group___e_c___e_r_r_o_r___c_o_d_e_s___g_e_n_e_r_i_c_1gae45dc6c94a43aa671697ecc700555c22) or first error code different from [EC_E_ERROR](error-codes_generic.html.md#d3/d2f/group___e_c___e_r_r_o_r___c_o_d_e_s___g_e_n_e_r_i_c_1gae45dc6c94a43aa671697ecc700555c22) and [EC_E_INVALIDPARM](error-codes_generic.html.md#d3/d2f/group___e_c___e_r_r_o_r___c_o_d_e_s___g_e_n_e_r_i_c_1ga1e10d9022db11a708658c71b0dead2fe) of registered clients’ callback functions The maximum value for dwCode is defined by `EC_NOTIFY_APP_MAX_CODE` ## emIoCtl - EC_IOCTL_SET_NOTIFICATION_ENABLED The following notifications can be enabled or disabled. - [emNotify - EC_NOTIFY_SLAVE_STATECHANGED](api_slave_control.html.md#emnotify-ec-notify-slave-statechanged) (default Off) - [emNotify - EC_NOTIFY_SLAVES_STATECHANGED](api_slave_control.html.md#emnotify-ec-notify-slaves-statechanged) (default Off) - [emNotify - EC_NOTIFY_SLAVE_UNEXPECTED_STATE](api_diagnosis.html.md#emnotify-ec-notify-slave-unexpected-state) (default On) - [emNotify - EC_NOTIFY_SLAVES_UNEXPECTED_STATE](api_diagnosis.html.md#emnotify-ec-notify-slaves-unexpected-state) (default Off) - [emNotify - EC_NOTIFY_SLAVE_PRESENCE](api_busscan.html.md#emnotify-ec-notify-slave-presence) (default On) - [emNotify - EC_NOTIFY_SLAVES_PRESENCE](api_busscan.html.md#emnotify-ec-notify-slaves-presence) (default Off) - [emNotify - EC_NOTIFY_SLAVE_ERROR_STATUS_INFO](api_diagnosis.html.md#emnotify-ec-notify-slave-error-status-info) (default On) - [emNotify - EC_NOTIFY_SLAVES_ERROR_STATUS](api_diagnosis.html.md#emnotify-ec-notify-slaves-error-status) (default Off) - [emNotify - EC_NOTIFY_NOT_ALL_DEVICES_OPERATIONAL](api_diagnosis.html.md#emnotify-ec-notify-not-all-devices-operational) (default On) - [emNotify - EC_NOTIFY_CYCCMD_WKC_ERROR](api_diagnosis.html.md#emnotify-ec-notify-cyccmd-wkc-error) (default On) - [emNotify - EC_NOTIFY_SB_MISMATCH](api_busscan.html.md#emnotify-ec-notify-sb-mismatch) (default On) - [emNotify - EC_NOTIFY_SB_STATUS](api_busscan.html.md#emnotify-ec-notify-sb-status) (default On) - [emNotify - EC_NOTIFY_STATUS_SLAVE_ERROR](api_diagnosis.html.md#emnotify-ec-notify-status-slave-error) (default On) - [emNotify - EC_NOTIFY_FRAME_RESPONSE_ERROR](api_diagnosis.html.md#emnotify-ec-notify-frame-response-error) (default On) - [emNotify - EC_NOTIFY_HC_TOPOCHGDONE](api_busscan.html.md#emnotify-ec-notify-hc-topochgdone) (default On) - [emNotify - EC_NOTIFY_STATECHANGED](#emnotify-ec-notify-statechanged) (default On) - [emNotify - EC_NOTIFY_COE_INIT_CMD](mbx_coe.html.md#emnotify-ec-notify-coe-init-cmd) (default Off) - `EC_NOTIFY_JUNCTION_RED_CHANGE` (default Off) - [emNotify - EC_NOTIFY_ALL_DEVICES_OPERATIONAL](api_diagnosis.html.md#emnotify-ec-notify-all-devices-operational) (default Off) - `EC_NOTIFY_DC_STATUS` (default On) - `EC_NOTIFY_DC_SLV_SYNC` (default On) - `EC_NOTIFY_DCM_SYNC` (default On) - [emNotify - EC_NOTIFY_SLAVE_INITCMD_RESPONSE_ERROR](api_diagnosis.html.md#emnotify-ec-notify-slave-initcmd-response-error) (default On) - `EC_NOTIFY_REFCLOCK_PRESENCE` (default Off) - `EC_NOTIFY_DCX_SYNC` (default On) - `EC_NOTIFY_HC_DETECTADDGROUPS` (default On) - [emNotify - EC_NOTIFY_FRAMELOSS_AFTER_SLAVE](api_busscan.html.md#emnotify-ec-notify-frameloss-after-slave) (default On) - [emNotify - EC_NOTIFY_ETH_LINK_NOT_CONNECTED](api_diagnosis.html.md#emnotify-ec-notify-eth-link-not-connected) (default On) - [emNotify - EC_NOTIFY_S2SMBX_ERROR](api_diagnosis.html.md#emnotify-ec-notify-s2smbx-error) (default On) - [emNotify - EC_NOTIFY_SLAVE_INITCMD_WKC_ERROR](api_diagnosis.html.md#emnotify-ec-notify-slave-initcmd-wkc-error) (default On) - [emNotify - EC_NOTIFY_BAD_CONNECTION](api_diagnosis.html.md#emnotify-ec-notify-bad-connection) (default On) ### EC_IOCTL_SET_NOTIFICATION_ENABLED Set notification enabled state. With [EC_T_SET_NOTIFICATION_ENABLED_PARMS::dwCode](#d6/ddc/struct_e_c___t___s_e_t___n_o_t_i_f_i_c_a_t_i_o_n___e_n_a_b_l_e_d___p_a_r_m_s_1ae1b2f429de202edb4e017449955a8800) set to EC_ALL_NOTIFICATIONS, all notifications can be changed at once. [EC_T_SET_NOTIFICATION_ENABLED_PARMS::dwEnabled](#d6/ddc/struct_e_c___t___s_e_t___n_o_t_i_f_i_c_a_t_i_o_n___e_n_a_b_l_e_d___p_a_r_m_s_1a322df8c32453561c2be96821b3d3e1db) set to EC_NOTIFICATION_DEFAULT, resets to default. * **Parameters:** * **pbyInBuf** – [in] Pointer to [EC_T_SET_NOTIFICATION_ENABLED_PARMS](#d6/ddc/struct_e_c___t___s_e_t___n_o_t_i_f_i_c_a_t_i_o_n___e_n_a_b_l_e_d___p_a_r_m_s). * **dwInBufSize** – [in] Size of the input buffer provided at pbyInBuf in bytes * **pbyOutBuf** – [out] Should be set to EC_NULL * **dwOutBufSize** – [in] Should be set to 0 * **pdwNumOutData** – [out] Should be set to EC_NULL * **Returns:** [EC_E_NOERROR](error-codes_generic.html.md#d3/d2f/group___e_c___e_r_r_o_r___c_o_d_e_s___g_e_n_e_r_i_c_1ga8c8419c32e88e73d940a4501fe427116) or error code ### struct EC_T_SET_NOTIFICATION_ENABLED_PARMS ### Public Members ### [EC_T_DWORD](toc_api.html.md#_CPPv410EC_T_DWORD) dwClientId [in] Client ID, 0: Master ### [EC_T_DWORD](toc_api.html.md#_CPPv410EC_T_DWORD) dwCode [in] Notification code or EC_ALL_NOTIFICATIONS ### [EC_T_DWORD](toc_api.html.md#_CPPv410EC_T_DWORD) dwEnabled [in] Enable, disable or reset to default notification. See EC_NOTIFICATION_ flags. Notifications are given to clients if enabled for dwClientId = 0 AND corresponding dwClientId. ## emIoCtl - EC_IOCTL_GET_NOTIFICATION_ENABLED ### EC_IOCTL_GET_NOTIFICATION_ENABLED The enabled state of notifications can be retrieved using [EC_IOCTL_GET_NOTIFICATION_ENABLED](#d0/d35/_ec_io_ctl_8h_1a925565a04161b26d801353adb08054dd). * **Parameters:** * **pbyInBuf** – [in] Pointer to [EC_T_GET_NOTIFICATION_ENABLED_PARMS](#dc/d03/struct_e_c___t___g_e_t___n_o_t_i_f_i_c_a_t_i_o_n___e_n_a_b_l_e_d___p_a_r_m_s) * **dwInBufSize** – [in] Size of the input buffer provided at pbyInBuf in bytes * **pbyOutBuf** – [out] Pointer to EC_T_BOOL to carry out current enable set * **dwOutBufSize** – [in] Size of the output buffer provided at pbyOutBuf in bytes * **pdwNumOutData** – [out] Pointer to EC_T_DWORD. Amount of bytes written to the output buffer * **Returns:** [EC_E_NOERROR](error-codes_generic.html.md#d3/d2f/group___e_c___e_r_r_o_r___c_o_d_e_s___g_e_n_e_r_i_c_1ga8c8419c32e88e73d940a4501fe427116) or error code ### struct EC_T_GET_NOTIFICATION_ENABLED_PARMS ### Public Members ### [EC_T_DWORD](toc_api.html.md#_CPPv410EC_T_DWORD) dwClientId [in] Client ID, 0: Master ### [EC_T_DWORD](toc_api.html.md#_CPPv410EC_T_DWORD) dwCode [in] Notification code #### SEE ALSO [emIoCtl - EC_IOCTL_SET_NOTIFICATION_ENABLED](#emioctl-ec-ioctl-set-notification-enabled)