6.5. 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.
6.5.1. 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 (*EC_PF_NOTIFY)(EC_T_DWORD dwCode, EC_T_NOTIFYPARMS *pParms)
6.5.2. 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 statedwInBufSize: [in] Size of the input buffer provided at pbyInBuf in bytespbyOutBuf: [out] Should be set to EC_NULLdwOutBufSize: [in] Should be set to 0pdwNumOutData: [out] Should be set to EC_NULL
See also
emIoCtl - EC_IOCTL_SET_NOTIFICATION_ENABLED for how to control the deactivation
6.5.3. emNotify - EC_NOTIFY_XXXX
Notification about an error.
- emNotify - EC_NOTIFY_XXXX
- Parameter
pbyInBuf: [in] Pointer to data of type EC_T_ERROR_NOTIFICATION_DESCdwInBufSize: [in] Size of the input buffer provided at pbyInBuf in bytespbyOutBuf: [out] Should be set to EC_NULLdwOutBufSize: [in] Should be set to 0pdwNumOutData: [out] Should be set to EC_NULL
6.5.4. Feature Pack MainDevice Redundancy Notifcations
See also
Feature Pack “MainDevice Redundancy”
6.5.5. emNotifyApp
By calling this function the generic notification callback function setup by emRegisterClient() is called for all clients including RAS.
-
static EC_T_DWORD ecatNotifyApp(EC_T_DWORD dwCode, EC_T_NOTIFYPARMS *pParms)
-
EC_T_DWORD emNotifyApp(EC_T_DWORD dwInstanceID, EC_T_DWORD dwCode, EC_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 or first error code different from EC_E_ERROR and EC_E_INVALIDPARM of registered clients’ callback functions
The maximum value for dwCode is defined by EC_NOTIFY_APP_MAX_CODE
6.5.6. emIoCtl - EC_IOCTL_SET_NOTIFICATION_ENABLED
The following notifications can be enabled or disabled.
emNotify - EC_NOTIFY_SLAVE_STATECHANGED (default Off)
emNotify - EC_NOTIFY_SLAVES_STATECHANGED (default Off)
emNotify - EC_NOTIFY_SLAVE_UNEXPECTED_STATE (default On)
emNotify - EC_NOTIFY_SLAVES_UNEXPECTED_STATE (default Off)
emNotify - EC_NOTIFY_SLAVE_PRESENCE (default On)
emNotify - EC_NOTIFY_SLAVES_PRESENCE (default Off)
emNotify - EC_NOTIFY_SLAVE_ERROR_STATUS_INFO (default On)
emNotify - EC_NOTIFY_SLAVES_ERROR_STATUS (default Off)
emNotify - EC_NOTIFY_NOT_ALL_DEVICES_OPERATIONAL (default On)
emNotify - EC_NOTIFY_CYCCMD_WKC_ERROR (default On)
emNotify - EC_NOTIFY_SB_MISMATCH (default On)
emNotify - EC_NOTIFY_SB_STATUS (default On)
emNotify - EC_NOTIFY_STATUS_SLAVE_ERROR (default On)
emNotify - EC_NOTIFY_FRAME_RESPONSE_ERROR (default On)
emNotify - EC_NOTIFY_HC_TOPOCHGDONE (default On)
emNotify - EC_NOTIFY_STATECHANGED (default On)
emNotify - EC_NOTIFY_COE_INIT_CMD (default Off)
EC_NOTIFY_JUNCTION_RED_CHANGE(default Off)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 (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 (default On)
emNotify - EC_NOTIFY_ETH_LINK_NOT_CONNECTED (default On)
emNotify - EC_NOTIFY_S2SMBX_ERROR (default On)
emNotify - EC_NOTIFY_SLAVE_INITCMD_WKC_ERROR (default On)
emNotify - EC_NOTIFY_BAD_CONNECTION (default On)
-
EC_IOCTL_SET_NOTIFICATION_ENABLED
Set notification enabled state. With EC_T_SET_NOTIFICATION_ENABLED_PARMS::dwCode set to EC_ALL_NOTIFICATIONS, all notifications can be changed at once. EC_T_SET_NOTIFICATION_ENABLED_PARMS::dwEnabled set to EC_NOTIFICATION_DEFAULT, resets to default.
- Parameters
pbyInBuf – [in] Pointer to EC_T_SET_NOTIFICATION_ENABLED_PARMS.
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 or error code
Notifications are given to clients if enabled for dwClientId = 0 AND corresponding dwClientId.
6.5.7. 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.
- Parameters
pbyInBuf – [in] Pointer to EC_T_GET_NOTIFICATION_ENABLED_PARMS
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 or error code