3.8. EtherCAT® traffic logging in application
emLogFrameEnable()
emLogFrameDisable()
All network traffic can be recorded by starting EcMasterDemo with the parameter -rec. For this EcMasterDemo needs to be compiled with preprocessor definition INCLUDE_PCAP_RECORDER defined.
See class CPcapRecorder in EcLogging.h/cpp.
EtherCAT® traffic logging Example
EC_T_VOID /* EC_FNCALL */ LogFrameHandler(EC_T_VOID* /* pvContext */,
EC_T_DWORD dwLogFlags, EC_T_DWORD dwFrameSize, EC_T_BYTE* pbyFrame)
{
EC_T_WORD wFrameType = EC_ETHFRM_GET_FRAMETYPE(pbyFrame);
EcLogMsg(EC_LOG_LEVEL_VERBOSE_CYC, (pEcLogContext, EC_LOG_LEVEL_VERBOSE_CYC,
"%d: LogFrameHandler(): Type: 0x%04X (%s, %s %s), length: %d bytes\n", wFrameType,
((0 != (dwLogFlags & EC_LOG_FRAME_FLAG_RED_FRAME)) ? "RED" : "MAIN"),
((0 != (dwLogFlags & EC_LOG_FRAME_FLAG_RX_FRAME)) ? "RX" : "TX"),
((0 != (dwLogFlags & EC_LOG_FRAME_FLAG_ACYC_FRAME)) ? "acyclic" : "cyclic"),
dwFrameSize));
}
/* setup callback function to log EtherCAT network traffic */
EC_T_VOID* pvMyAppContext = this;
dwRes = emLogFrameEnable(dwInstanceId, LogFrameHandler, pvMyAppContext);
/* disable frame logging callback */
dwRes = emLogFrameDisable(dwInstanceId);