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

Sebastien Blanchet blanchet at iram.fr
Mon Jul 28 09:51:30 CEST 2014


Hi Gavin,

You are right:
For way #1, if I use ecrt_master() instead of ec_master(), it works.

Anyway I will use the way #2, as you told me.

thank for you help
---
sebastien

On 07/28/2014 07:54 AM, Gavin Lambert wrote:
> On 26 July 2014, quoth Sebastien Blanchet:
>> 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'"
>
> That's because the API call is "ecrt_master", not "ec_master".  If you
> correct that, then this should work, but it's not the most efficient method.
>
>> // 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
>
> This is the correct method.
>
>> // 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++;
>>       }
>
> Don't do this (unless you actually want to keep each slave's info).
> Remember that if you're using the usermode lib, each time you call a master
> API you are making a user->kernel->user transition, which will cause a
> performance hit.  While it doesn't really matter at this point (since you're
> still pre-realtime) making excessive API calls is not a good habit to get
> into.
>


-- 
Sebastien BLANCHET



More information about the Etherlab-users mailing list