[etherlab-users] how to get slave count from userspace ?

Sebastien Blanchet blanchet at iram.fr
Fri Jul 25 18:00:29 CEST 2014


Hi,

I would like to know which is the right way to get the number of slaves on the 
EtherCAT bus in a usespace program.

I have tried 3 ways:

// way #1:
     ec_master_info_t masterInfo;
     ec_master_t* master = ecrt_request_master(0);
     ec_master( master, &masterInfo );

     // the answer should be in masterInfo.slave_count
     // but it does not work because the compiler says
     //"error: invalid use of incomplete type ‘struct ec_master’"

// way #2
     ec_master_state_t state;
     ec_master_t* master = ecrt_request_master(0);
     ecrt_master_state( master, &state );

     // it seems to work,
     // the answer is in state.slaves_responding


// way #3  (very ugly)
     ec_slave_info_t dummySlaveInfo;
     int slave_count = 0;
     ec_master_t* master = ecrt_request_master(0);

     while (!ecrt_master_get_slave( master, slave_count, &dummySlaveInfo)) {
	slave_count++;
     }

     // it work but there is warning on stderr when
     // ecrt_master_get_slave fails at the end


for the moment I use way #2, but I wonder if is the best way to do.

regards,
-- 
Sebastien BLANCHET



More information about the Etherlab-users mailing list