3.7. Error detection and diagnosis
The EC-Master API functions generally return EC_E_NOERROR or an error code.
One of the parameters that the client must set when registering with the EC-Master is a generic notification callback function (emNotify()). If an error is detected, the EC-Master calls this function.
The EC-Master log messages are enabled if EC_T_LOG_PARMS is configured as described in emInitMaster() or configured using emSetLogParms().
3.7.1. Cyclic cmd WKC validation and Frame Loss
New input values received from the SubDevices will be written into the input process data memory only if the WKC of the corresponding datagram is not 0 and not greater than the configured WKC value.
It is possible to clear INPUTs in the process data image if an error is detected using the following IOCTLs:
3.7.2. Working Counter (WKC) State in Diagnosis Image
Each cyclic Process Data cmd has its own WKC State bit in the diagnosis image. The state is updated on frame receiving, frame loss detection or link disconnection. All process data variables within a datagram have the same WKC State value. If the WKC value of the received datagram is not as expected, the WKC State bit is set to 1 for this datagram (error). In case of MainDevice Sync Units (MSU) if all the commands related to the MSU return WKC 0, the WKC State will be set to 1.
The WKC State offset within the Diagnosis Image is available at EC_T_CFG_SLAVE_INFO and EC_T_PROCESS_VAR_INFO_EX, EC_T_MSU_INFO see emGetDiagnosisImagePtr(), emGetCfgSlaveInfo(), emGetSlaveInpVarInfoEx(), emGetSlaveOutpVarInfoEx(), emGetMasterSyncUnitInfo().
The application can check the WKC State of a variable e.g. as follows:
EC_T_CFG_SLAVE_INFO oSlaveInfo;
EC_T_BYTE* pbyDiagnosisImage = emGetDiagnosisImagePtr();
EC_T_BYTE byWkcState = 1;
if (EC_NULL != pbyDiagnosisImage)
{
if (EC_NOERROR == emGetCfgSlaveInfo(EC_TRUE, 2302, &oSlaveInfo))
{
EC_GETBITS(pbyDiagnosisImage, &byWkcState, oSlaveInfo.wWkcStateDiagOffsOut[0], 1);
}
}
if (1 == byWkcState)
{
/* ... error ... */
}
3.7.2.1. Behavior in case of automatically adjusted expected WKC value
Optionally, the expected WKC value can be automatically adjusted according to the state and the presence of the SubDevices. See emIoCtl - EC_IOCTL_SET_AUTO_ADJUST_CYCCMD_WKC_ENABLED. The WKC State bits change synchronized to the corresponding notification, e.g. on link disconnection all SubDevices disappear and the behavior is as follows:
All WKC State bits are set to 1 as missing data is not expected.
The MainDevice notifies the application about the link disconnection and the disappearing of SubDevices.
All WKC State bits are set to 0 as it is now expected to have no process data if all SubDevices are absent.
3.7.3. MainDevice Sync Units (MSU)
MSUs are useful in grouping specific data (into consistency units)
Process Image: Variables are stored together within one memory block
Error checking: Own datagram(s) allow individual WKC state check (consistency unit)
Figure out the MSU offsets by calling the functions emGetMasterSyncUnitInfoNumOf() and emGetMasterSyncUnitInfo(), as described in the corresponding documentation.