文章
Cable redundancy example
refer to EtherCAT MainDevice Application Developers Manual
Demo
Demostrate how to support Cable Redundancy feature with esd EtherCAT Master stack.

Example code
Please get the source code ecmCableRedundancy.c, and copy the ENI file cable_redundancy_three_ecxdio8.xml to the same folder as the executable file.
Run the compiled executable file, during execution, remove one cable, the system is still running properly. Please check the video
static int CycleHandler(ECM_HANDLE hndDevice, int error){
if(!inop) return 0;
if (i==8)
{
*pucDo = 0;
i=0;
j++;
if(j<3)
pucDo++;
else{
pucDo-=2;
j=0;
}
}
*pucDo = ucData[i];
i++;
return 0;
}
ECM_INIT(cfgInitData);
cfgInitData.Config.File.pszEniFile = "./cable_redundancy_three_ecxdio8.xml";
cfgInitData.ulFlags |= ECM_FLAG_CFG_IGNORE_SRC_MAC;
cfgInitData.cfgDataDevice.ulFlags |= ECM_FLAG_DEVICE_REDUNDANCY;
pNicList = calloc(2, sizeof(ECM_NIC));
//Intel ethernet adapter as primary adapter
pNicList[0].macAddr.b[0] = 0x74;
pNicList[0].macAddr.b[1] = 0x46;
pNicList[0].macAddr.b[2] = 0xa0;
pNicList[0].macAddr.b[3] = 0xab;
pNicList[0].macAddr.b[4] = 0xd2;
pNicList[0].macAddr.b[5] = 0x30;
ECM_INIT_MAC(macPrimary, pNicList[0].macAddr);
//Realtek ethernet adapter as redundant adapter
pNicList[1].macAddr.b[0] = 0x08;
pNicList[1].macAddr.b[1] = 0x57;
pNicList[1].macAddr.b[2] = 0x00;
pNicList[1].macAddr.b[3] = 0xe9;
pNicList[1].macAddr.b[4] = 0x5b;
pNicList[1].macAddr.b[5] = 0xc9;
ECM_INIT_MAC(macRedundant,pNicList[1].macAddr);
cfgInitData.cfgDataDevice.macAddr[0]=macPrimary;
cfgInitData.cfgDataDevice.macAddr[1]=macRedundant;
result = ecmReadConfiguration(&cfgInitData, &hndDevice, &hndMaster);
if (result != ECM_SUCCESS) {
printf("Reading configuration failed with %s\n", ecmResultToString(result));
ecmInitLibrary(NULL);
return(result);
}