文章
ECX-DIO8 quick guide
EC Master Demo code to control ECX-DIO8
ecmDualOutput.c
eni_dual_ecx-dio8.xml
The demo system consists of 2 ECX-DIO8 devices, which demonstrates that the output LEDs of the 2 devices are sequenially lit to form a loop. Don't forget to modify the NIC MAC address <Source>7446A0ABD230</Source> of the PC that is running esd EtherCAT Master before you use it.
//LED light sequence
// 1.4(0x08), 1.3(0x04), 1.2(0x02), 1.1(0x01),
// 2.4(0x08), 2.3(0x04), 2.2(0x02), 2.1(0x01),
// 2.5(0x10), 2.6(0x20), 2.7(0x40), 2.8(0x80),
// 1.5(0x10), 1.6(0x20), 1.7(0x40), 1.8(0x80),
for (i=0;i<ulLoops;i++){
for(j=0x8;j>=0x1;j=j>>1){
*pucDo = j;
mySleep();
}
*pucDo = 0;
pucDo = pucDo + 3;
for(j=0x8;j>=0x1;j=j>>1){
*pucDo = j;
mySleep();
}
*pucDo = 0;
for(j=0x10;j<=0x80;j=j<<1){
*pucDo = j;
mySleep();
}
*pucDo = 0;
pucDo = pucDo - 3;
for(j=0x10;j<=0x80;j=j<<1){
*pucDo = j;
mySleep();
}
}
EC Master Demo code by putting output LEDs logic code into Cyclic Callback handler
ecmDualOutputCycleHandler.c
eni_dual_ecx-dio8.xml
ecx-dio8_outpuleds_loop.mp4
The demo system consists of 2 ECX-DIO8 devices like above, which demonstrates that the output LEDs of the 2 devices are sequenially lit to form a loop. In addition, it also has speed change.
static int CycleHandler(){
//LED light sequence
// 1.4(0x08), 1.3(0x04), 1.2(0x02), 1.1(0x01),
// 2.4(0x08), 2.3(0x04), 2.2(0x02), 2.1(0x01),
// 2.5(0x10), 2.6(0x20), 2.7(0x40), 2.8(0x80),
// 1.5(0x10), 1.6(0x20), 1.7(0x40), 1.8(0x80),
static uint8_t ucData[16]={0x08,0x04,0x02,0x01,0x08,0x04,0x02,0x01,0x10,0x20,0x40,0x80,0x10,0x20,0x40,0x80};
static int8_t i=0;
if (i == 4) {
*pucDo = 0;
pucDo = pucDo + 3;
}
if (i == 12) {
*pucDo = 0;
pucDo = pucDo - 3;
}
if (i == 16) {
i=0;
}
*pucDo = ucData[i];
i++;
}
######################################
ProcCtrl.ulAcyclicPeriod = 1000;
ProcCtrl.ulAcyclicPrio = ECM_PRIO_DEFAULT;
// ProcCtrl.ulCyclicPeriod = cfgInitData.cfgDataDevice.ulCycleTime;
ProcCtrl.ulCyclicPeriod = 100000;
ProcCtrl.ulCyclicPrio = ECM_PRIO_DEFAULT;
ProcCtrl.pfnHandler = CycleHandler;
// ProcCtrl.pfnBeginCycle = CycleStartHandler;
// ProcCtrl.pfnEndCycle = CycleEndHandler;
result = ecmProcessControl(hndDevice, &ProcCtrl);
######################################
do
{
ecmSleep(100);
if (ProcCtrl.ulCyclicPeriod > 10000) {
if (ProcCtrl.ulCyclicPeriod == 40000)
ecmSleep(5000);
if (ProcCtrl.ulCyclicPeriod == 20000)
ecmSleep(5000);
ProcCtrl.ulCyclicPeriod -= 500;
}
else
break;
result = ecmProcessControl(hndDevice, &ProcCtrl);
if (result != ECM_SUCCESS) {
// printf("Creating background worker threads failed with %s\n", ecmResultToString(result));
ecmDetachMaster(hndMaster);
ecmDeleteMaster(hndMaster);
ecmDeleteDevice(hndDevice);
ecmInitLibrary(NULL);
return(-1);
} else {
printf("Worker thread cycle times (microseconds) (Cyclic: %d)\n", ProcCtrl.ulCyclicPeriod);
}
}while (1);