10. Generic notification interface
One of the parameters the client has to set when registering with the EC-Monitor is a generic notification callback function ( emonNotify()
). This function is called every time an event occurs about which the client needs 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 master, sending raw commands). In such cases the behavior is undefined. Only EtherCAT® functions which are explicitly marked to be callable within emonNotify()
may be called.
This callback function is usually called in the context of the EC-Monitor timer thread or the EtherCAT® Real-time Ethernet Driver receiver thread. 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.
10.1. Notification callback
-
typedef EC_T_DWORD (*EC_PF_NOTIFY)(EC_T_DWORD dwCode, EC_T_NOTIFYPARMS *pParms)
10.2. emonNotifyApp
By calling this function the generic notification callback function setup by emonRegisterClient()
is called.
-
EC_T_DWORD emonNotifyApp(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
10.3. Enable/Disable notifications
All notifications can be enabled or disabled. By default, all notifications are enabled except for:
EC_NOTIFY_SLAVE_STATECHANGED
EC_NOTIFY_SLAVES_STATECHANGED
EC_NOTIFY_SLAVES_PRESENCE
EC_NOTIFY_REFCLOCK_PRESENCE
EC_NOTIFY_SLAVES_UNEXPECTED_STATE
EC_NOTIFY_SLAVES_ERROR_STATUS
EC_NOTIFY_COE_INIT_CMD
EC_NOTIFY_SLAVE_REGISTER_TRANSFER
10.3.1. emonIoControl - 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.
- emonIoControl - EC_IOCTL_SET_NOTIFICATION_ENABLED
- Parameter
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_NULLdwOutBufSize
: [in] Should be set to 0pdwNumOutData
: [out] Should be set to EC_NULL
-
struct EC_T_SET_NOTIFICATION_ENABLED_PARMS
Public Members
-
EC_T_DWORD dwCode
[in] Notification code or EC_ALL_NOTIFICATIONS
-
EC_T_DWORD dwEnabled
[in] Enable, disable or reset to default notification. See EC_NOTIFICATION_ flags
-
EC_T_DWORD dwCode
10.3.2. emonIoControl - EC_IOCTL_GET_NOTIFICATION_ENABLED
Get notification enabled state.
- emonIoControl - EC_IOCTL_GET_NOTIFICATION_ENABLED
- Parameter
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.
10.4. Status notifications
10.4.1. emonNotify - EC_NOTIFY_STATECHANGED
Notification about a change in the master’s operational state.
- emonNotify - EC_NOTIFY_STATECHANGED
- Parameter
pbyInBuf
: [in] Pointer to data of type EC_T_STATECHANGE which contains the old and the new master operational state.dwInBufSize
: [in] Size of the input buffer provided at pbyInBuf in bytes.pbyOutBuf
: [out] Should be set to EC_NULLdwOutBufSize
: [in] Should be set to 0pdwNumOutData
: [out] Should be set to EC_NULL
10.4.2. emonNotify - EC_NOTIFY_SB_STATUS
Scan bus status notification.
- emonNotify - EC_NOTIFY_SB_STATUS
- Parameter
pbyInBuf
: [in] Pointer to EC_T_SB_STATUS_NTFY_DESCdwInBufSize
: [in] Size of the input buffer provided at pbyInBuf in bytes.pbyOutBuf
: [out] Should be set to EC_NULLdwOutBufSize
: [in] Should be set to 0pdwNumOutData
: [out] Should be set to EC_NULL
10.4.3. emonNotify - EC_NOTIFY_SB_MISMATCH
This notification is triggered when the bus scan detects a discrepancy between connected slaves and configuration due to unexpected slaves or missing mandatory slaves. In case of permanent frame loss no slaves can be found although the slaves are connected.
- emonNotify - EC_NOTIFY_SB_MISMATCH
- Parameter
pbyInBuf
: [in] Pointer to EC_T_SB_MISMATCH_DESCdwInBufSize
: [in] Size of the input buffer provided at pbyInBuf in bytes.pbyOutBuf
: [out] Should be set to EC_NULLdwOutBufSize
: [in] Should be set to 0pdwNumOutData
: [out] Should be set to EC_NULL
10.4.4. emonNotify - EC_NOTIFY_HC_TOPOCHGDONE
This notification is triggered when topology change has completely processed.
- emonNotify - EC_NOTIFY_HC_TOPOCHGDONE
- Parameter
pbyInBuf
: [in] Pointer to EC_T_DWORD (EC_E_NOERROR on success, Error code otherwise)dwInBufSize
: [in] sizeof(EC_T_DWORD).pbyOutBuf
: [out] Should be set to EC_NULLdwOutBufSize
: [in] Should be set to 0pdwNumOutData
: [out] Should be set to EC_NULL
10.4.5. emonNotify - EC_NOTIFY_SLAVE_PRESENCE
This notification is given, if slave appears or disappears from the network.
- emonNotify - EC_NOTIFY_SLAVE_PRESENCE
- Parameter
pbyInBuf
: [in] Pointer to EC_T_SLAVE_PRESENCE_NTFY_DESCdwInBufSize
: [in] Size of the input buffer provided at pbyInBuf in bytes.pbyOutBuf
: [out] Should be set to EC_NULLdwOutBufSize
: [in] Should be set to 0pdwNumOutData
: [out] Should be set to EC_NULL
Disconnecting the slave from the network, powering it off or a bad connection can produce this notification.
10.4.6. emonNotify - EC_NOTIFY_SLAVE_STATECHANGED
This notification is triggered when a slave has changed its EtherCAT® state. This notification is disabled by default.
- emonNotify - EC_NOTIFY_SLAVE_STATECHANGED
- Parameter
pbyInBuf
: [in] Pointer to EC_T_SLAVE_STATECHANGED_NTFY_DESCdwInBufSize
: [in] Size of the input buffer provided at pbyInBuf in bytes.pbyOutBuf
: [out] Should be set to EC_NULLdwOutBufSize
: [in] Should be set to 0pdwNumOutData
: [out] Should be set to EC_NULL
See also
emonIoControl - EC_IOCTL_SET_NOTIFICATION_ENABLED to enable notification.
10.4.7. emonNotify - EC_NOTIFY_SLAVE_REGISTER_TRANSFER
This notification is triggered when a slave register transfer is completed.
To avoid excessive triggering of the notification, registers that are read by the EtherCAT® master at regular intervals are not notified. These are the following registers:
AL-Status (0x0130)
RX Error Counter, Forwarded RX Error Counter, ECAT Processing Unit Error Counter, PDI Error Counter, PDI Error Code, Lost Link Counter (0x0300:0x0314)
SII EEPROM Interface (0x0500:0x050F)
Registers above 0x1000
This notification is disabled by default.
- emonNotify - EC_NOTIFY_SLAVE_REGISTER_TRANSFER
- Parameter
pbyInBuf
: [in] Pointer to EC_T_SLAVEREGISTER_TRANSFER_NTFY_DESCdwInBufSize
: [in] Size of the input buffer provided at pbyInBuf in bytes.pbyOutBuf
: [out] Should be set to EC_NULLdwOutBufSize
: [in] Should be set to 0pdwNumOutData
: [out] Should be set to EC_NULL
See also
emonIoControl - EC_IOCTL_SET_NOTIFICATION_ENABLED to enable notification.
10.5. Error notifications
For each error an error ID (error code) will be defined. This error ID will be used as the notification code when emonNotify()
is called. In addition to this notification code the second parameter given to emonNotify()
contains a pointer to an error notification descriptor of type EC_T_ERROR_NOTIFICATION_DESC
. This error notification descriptor contains detailed information about the error.
-
struct EC_T_ERROR_NOTIFICATION_DESC
Public Members
-
union _EC_T_ERROR_NOTIFICATION_PARM
Public Members
-
EC_T_WKCERR_DESC WkcErrDesc
WKC error descriptor
-
EC_T_FRAME_RSPERR_DESC FrameRspErrDesc
Frame response error descriptor
-
EC_T_SLAVE_ERROR_INFO_DESC SlaveErrInfoDesc
Slave Error Info Descriptor
-
EC_T_MBOX_FOE_ABORT_DESC FoeErrorDesc
FoE error code and string
-
EC_T_PDIWATCHDOG_DESC PdiWatchdogDesc
PDI watchdog expired
-
EC_T_COMMUNICATION_TIMEOUT_NTFY_DESC CommunicationTimeoutDesc
Communication timeout descriptor
-
EC_T_TAP_LINK_STATUS_NTFY_DESC TapLinkStatusDesc
Tap link status
-
EC_T_WKCERR_DESC WkcErrDesc
-
union _EC_T_ERROR_NOTIFICATION_PARM
If the pointer to this descriptor exists the detailed error information (e.g. information about the slave) is stored in the appropriate structure of a union. These error information structures are described in the following sections.
10.5.1. emonNotify - EC_NOTIFY_NOT_ALL_DEVICES_OPERATIONAL
When processing cyclic frames the EtherCAT® master checks whether all slaves are still in OPERATIONAL state. If at least one slave device is not OPERATIONAL this error will be indicated.
10.5.2. emonNotify - EC_NOTIFY_ALL_DEVICES_OPERATIONAL
When processing cyclic frames the EtherCAT® master checks whether all slaves are still in OPERATIONAL state. This will be notified after emonNotify - EC_NOTIFY_NOT_ALL_DEVICES_OPERATIONAL and all the slaves are back in OPERATIONAL state.
10.5.3. emonNotify - EC_NOTIFY_CLIENTREGISTRATION_DROPPED
This notification will be indicated if the client registration was dropped because emonConfigureNetwork()
was called by another thread.
EC_T_DWORD dwDeinitForConfiguration; /* 0 = terminating Master, 1 = restarting Master */
10.5.4. emonNotify - EC_NOTIFY_CYCCMD_WKC_ERROR
To update the process data some EtherCAT® commands will be sent cyclically by the external master. These commands will address one or multiple slaves. These EtherCAT® commands contain a working counter which has to be incremented by each slave that is addressed. The working counter will be checked after the EtherCAT® command is received by the monitor.
If the expected working counter will not match to the working counter of the received command the error EC_NOTIFY_CYCCMD_WKC_ERROR will be indicated. The working counter value expected by the monitor is determined by the EtherCAT® configuration (XML) file for each cyclic EtherCAT® command (section Config/Cyclic/Frame/Cmd/Cnt).
Detailed error information are stored in structure EC_T_WKCERR_DESC
of EC_T_ERROR_NOTIFICATION_DESC
.
-
struct EC_T_WKCERR_DESC
Public Members
-
EC_T_SLAVE_PROP SlaveProp
Slave properties, content is undefined in case of cyclic WKC_ERROR
-
EC_T_SLAVE_PROP SlaveProp
-
struct EC_T_SLAVE_PROP
-
EC_T_WORD wStationAddress
-
EC_T_WORD wAutoIncAddr
-
EC_T_CHAR achName[MAX_STD_STRLEN]
-
EC_T_WORD wStationAddress
10.5.5. emonNotify - EC_NOTIFY_FRAME_RESPONSE_ERROR
This notification will be indicated if the actually received Ethernet frame does not match to the frame expected or if a expected frame was not received.
-
struct EC_T_FRAME_RSPERR_DESC
Public Members
-
EC_T_FRAME_RSPERR_TYPE EErrorType
Frame response error type
-
EC_T_BYTE byEcCmdHeaderIdxSet
Expected IDX value, this value is valid only for acyclic frames in case EErrorType is not equal to eRspErr_UNEXPECTED
-
EC_T_FRAME_RSPERR_TYPE EErrorType
10.5.6. emonNotify - EC_NOTIFY_STATUS_SLAVE_ERROR
When processing cyclic frames, the EC-Monitor checks whether the ERROR bit in the AL-STATUS register is set for at least one slave. In this case, this notification is triggered. If the EtherCAT® master determines the error information of the slave(s) signal an error, another notification emonNotify - EC_NOTIFY_SLAVE_ERROR_STATUS_INFO with more precise error information is triggered.
10.5.7. emonNotify - EC_NOTIFY_SLAVE_ERROR_STATUS_INFO
This notification will be indicated if the EtherCAT® master reads the AL-STATUS and AL-STATUS-CODE registers and the slave signals an error in them. Detailed error information is stored in structure EC_T_SLAVE_ERROR_INFO_DESC
of EC_T_ERROR_NOTIFICATION_DESC
.
-
struct EC_T_SLAVE_ERROR_INFO_DESC
Public Members
-
EC_T_SLAVE_PROP SlaveProp
Slave properties
-
EC_T_SLAVE_PROP SlaveProp
10.5.8. emonNotify - EC_NOTIFY_PDIWATCHDOG
This notification will be indicated every time a PDI watchdog error is detected. Detailed error information is stored in structure EC_T_PDIWATCHDOG_DESC
of EC_T_ERROR_NOTIFICATION_DESC
.
-
struct EC_T_PDIWATCHDOG_DESC
Public Members
-
EC_T_SLAVE_PROP SlaveProp
Slave properties
-
EC_T_SLAVE_PROP SlaveProp
10.5.9. emonNotify - EC_NOTIFY_COMMUNICATION_TIMEOUT
This notification will be indicated if the EC-Monitor does not detect any EtherCAT® communication on the Ethernet tap for a parameterizable timeout. The descriptor of the notification contains information on which port of the Ethernet tap the timeout occurred.
10.5.10. emonNotify - EC_NOTIFY_TAP_LINK_STATUS
This notification will be indicated if the link status between EC-Monitor and Ethernet TAP device has changed.