Enthernet Code
Enthernet Code
DIIDevHeads IoT Integration Server
Created by Boss lady on 7/8/2024 in #code-review
Resolving "No EtherCAT Slaves Found" Error on BeagleBone AI with Embedded Linux
It seems like the problem might be with the network configuration or the way the EtherCAT library is initialized. Make sure your network configuration does not interfere with EtherCAT communication. Also, ensure the ec_init function is correctly initializing the network interface and you could add some debug prints in your code to ensure that the initialization steps are executed as expected. Modify your code like this to get more details:
#include <stdio.h>
#include <ethercat.h>

int main() {
printf("Initializing EtherCAT on eth0...\n");
if (ec_init("eth0") <= 0) {
fprintf(stderr, "Failed to initialize EtherCAT\n");
return 1;
}
printf("EtherCAT initialized.\n");

if (ec_config_init(FALSE) <= 0) {
fprintf(stderr, "No EtherCAT slaves found\n");
ec_close();
return 1;
}
printf("EtherCAT slaves found and configured.\n");

ec_config_map(&IOmap);
ec_configdc();

while (1) {
ec_send_processdata();
ec_receive_processdata(EC_TIMEOUTRET);

int torque = ec_slave[1].inputs[0];
printf("Torque: %d\n", torque);
usleep(500000);
}

ec_close();
return 0;
}
#include <stdio.h>
#include <ethercat.h>

int main() {
printf("Initializing EtherCAT on eth0...\n");
if (ec_init("eth0") <= 0) {
fprintf(stderr, "Failed to initialize EtherCAT\n");
return 1;
}
printf("EtherCAT initialized.\n");

if (ec_config_init(FALSE) <= 0) {
fprintf(stderr, "No EtherCAT slaves found\n");
ec_close();
return 1;
}
printf("EtherCAT slaves found and configured.\n");

ec_config_map(&IOmap);
ec_configdc();

while (1) {
ec_send_processdata();
ec_receive_processdata(EC_TIMEOUTRET);

int torque = ec_slave[1].inputs[0];
printf("Torque: %d\n", torque);
usleep(500000);
}

ec_close();
return 0;
}
14 replies