# Code example The example program EcMasterDemoDc demonstrates, in contrast to EcMasterDemo, how to programmatically configure DCM parameters and how the application can generate the DCM log. ### **DCM Configuration (optional)** ```cpp /* initialize the master */ dwRes = ecatInitMaster(&oInitParms); /* configure the master */ dwRes = ecatConfigureNetwork(eCnfType_Filename, (EC_T_BYTE*)"ENI.xml", (EC_T_DWORD)OsStrlen("ENI.xml")); /* register client */ EC_T_REGISTERRESULTS oRegisterClientResults; OsMemset(&oRegisterClientResults, 0, sizeof(EC_T_REGISTERRESULTS)); dwRes = ecatRegisterClient(EcMasterNotifyCallback, pAppContext, &oRegisterClientResults); /* configure DC */ EC_T_DC_CONFIGURE oDcConfigure; OsMemset(&oDcConfigure, 0, sizeof(EC_T_DC_CONFIGURE)); oDcConfigure.dwTimeout = ETHERCAT_DC_TIMEOUT; dwRes = ecatDcConfigure(&oDcConfigure); /* configure DCM Bus Shift */ EC_T_DCM_CONFIG oDcmConfig; OsMemset(&oDcmConfig, 0, sizeof(EC_T_DCM_CONFIG)); oDcmConfig.eMode = eDcmMode_BusShift; oDcmConfig.u.BusShift.nCtlSetVal = DCM_CONTROLLER_SETVAL_NANOSEC; oDcmConfig.u.BusShift.bLogEnabled = EC_TRUE; dwRes = ecatDcmConfigure(&oDcmConfig, 0 /* dwInSyncTimeout */); /* set EtherCAT devices to OPERATIONAL state */ dwRes = ecatSetMasterState(ETHERCAT_STATE_CHANGE_TIMEOUT, eEcatState_OP); ``` #### SEE ALSO [`emDcConfigure()`](dc_api.html.md#_CPPv413emDcConfigure10EC_T_DWORDPK17EC_T_DC_CONFIGURE) #### SEE ALSO [`emDcmConfigure()`](dcm_api.html.md#_CPPv414emDcmConfigure10EC_T_DWORDPK15EC_T_DCM_CONFIG10EC_T_DWORD) ### **DCM Log (optional)** ```cpp do { /* wait for next cycle (event from scheduler task) */ /* ... */ /* process all received frames (read new input values) */ dwRes = ecatExecJob(eUsrJob_ProcessAllRxFrames, &oJobParms); /* ... */ EC_T_CHAR* szDcmLog = EC_NULL; ecatDcmGetLog(&szDcmLog); if (EC_NULL != szDcmLog) { ((CAtEmLogging*)pEcLogContext)->LogDcm(szDcmLog); } /* ... */ } while (!pAppContext->bJobTaskShutdown); ``` #### SEE ALSO [`emDcmGetLog()`](dcm_api.html.md#_CPPv411emDcmGetLog10EC_T_DWORDPP9EC_T_CHAR)