[etherlab-users] write_sdo() function

Gavin Lambert gavinl at compacsort.com
Tue Jul 28 03:21:34 CEST 2015


It's not that easy - even the read in the example is oversimplified (it
assumes you always want to read), and reads are quite different from writes.

 

I'm not sure where you got ec_sdo_request_copy_data from, but the correct
way to access the data memory of a request is with ecrt_sdo_request_data,
which simply returns a pointer that you can read from or write to, eg. with
memcpy or one of the EC_READ/WRITE_* macros (as shown in the example).
Although I would hope that it's obvious that you're also doing it at the
wrong time.

 

But you're trying to create something that looks like a synchronous
function, and your colleagues will probably try to use it like one if you do
that, which won't work.  So don't go there.  You need to have a state
machine that knows whether a write is pending or not, and your function
needs to expose the fact that it's asynchronous, otherwise people will use
it incorrectly.

 

If you really don't want to deal with asynchrony then you can still use the
synchronous ecrt_master_sdo_download method to do writes - but you have to
call this on a different thread than the realtime thread and it may still
increase latency (and disturb the cyclic performance) of the realtime
thread.  Depending on your cyclic interval and how performance-critical your
EtherCAT system is, this may not be an issue for you.

 

From: etherlab-users [mailto:etherlab-users-bounces at etherlab.org] On Behalf
Of HASSAN ZAHRAEE Ali
Sent: Tuesday, 28 July 2015 03:47
To: etherlab-users at etherlab.org
Subject: [etherlab-users] write_sdo() function

 

Hi all,

 

I am trying to write a simplified ethercat communication module on top of
Igh master for some of my colleagues who do not want to know the details of
how the master works.

Based on the sdo_read() function in the examples provided with the master, I
have written the following write_sdo() function:

 

int write_sdo(        ec_sdo_request_t *sdo,       uint8_t *data)

{

  int sdo_write_ret = 0;

  size_t size = ecrt_sdo_request_data_size(sdo);

 

  switch (ecrt_sdo_request_state(sdo)) {

    case EC_REQUEST_UNUSED:

      ecrt_sdo_request_write(sdo); // trigger first read

      break;

    case EC_REQUEST_BUSY:

      fprintf(stderr, "Still busy...\n");

      break;

    case EC_REQUEST_SUCCESS:

      if(!(sdo_write_ret = ec_sdo_request_copy_data(sdo_server, data,
size))) {

        printf("Failed to write to SDO channel.\n");

      }

      ecrt_sdo_request_write(sdo); // trigger next read

      break;

  case EC_REQUEST_ERROR:

    fprintf(stderr, "Failed to write to SDO channel!\n");

    ecrt_sdo_request_write(sdo); // retry reading

    break;

  }

 

  return sdo_write_ret;

}

 

 

When compiling I get an undefined reference to `ec_sdo_request_copy_data'
error. I tried adding

EXPORT_SYMBOL(ec_sdo_request_copy_data);

at the end of /master/sdo_request.c and rebuild the master, but it didn't
help.

 

It would be great if someone could help with this issue.

 

Best Regards,

Ali

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.etherlab.org/pipermail/etherlab-users/attachments/20150728/8d8fbb98/attachment-0003.htm>


More information about the Etherlab-users mailing list