<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:"Arial Narrow";
panose-1:2 11 6 6 2 2 2 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal;
font-family:"Calibri",sans-serif;
color:windowtext;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-NZ link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='color:#1F497D'>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.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>I’m not sure where you got </span><span lang=EN-US style='font-family:"Arial Narrow",sans-serif'>ec_sdo_request_copy_data</span><span style='color:#1F497D'> 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.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>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.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>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.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><div style='border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt'><div><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span lang=EN-US style='mso-fareast-language:EN-NZ'>From:</span></b><span lang=EN-US style='mso-fareast-language:EN-NZ'> etherlab-users [mailto:etherlab-users-bounces@etherlab.org] <b>On Behalf Of </b>HASSAN ZAHRAEE Ali<br><b>Sent:</b> Tuesday, 28 July 2015 03:47<br><b>To:</b> etherlab-users@etherlab.org<br><b>Subject:</b> [etherlab-users] write_sdo() function<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span lang=FR>Hi all,<o:p></o:p></span></p><p class=MsoNormal><span lang=FR><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>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.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>Based on the sdo_read() function in the examples provided with the master, I have written the following write_sdo() function:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial Narrow",sans-serif'>int write_sdo( ec_sdo_request_t *sdo, uint8_t *data)<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial Narrow",sans-serif'>{<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial Narrow",sans-serif'> int sdo_write_ret = 0;<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial Narrow",sans-serif'> size_t size = ecrt_sdo_request_data_size(sdo);<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial Narrow",sans-serif'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial Narrow",sans-serif'> switch (ecrt_sdo_request_state(sdo)) {<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial Narrow",sans-serif'> case EC_REQUEST_UNUSED:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial Narrow",sans-serif'> ecrt_sdo_request_write(sdo); // trigger first read<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial Narrow",sans-serif'> break;<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial Narrow",sans-serif'> case EC_REQUEST_BUSY:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial Narrow",sans-serif'> fprintf(stderr, "Still busy...\n");<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial Narrow",sans-serif'> break;<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial Narrow",sans-serif'> case EC_REQUEST_SUCCESS:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial Narrow",sans-serif'> if(!(sdo_write_ret = ec_sdo_request_copy_data(sdo_server, data, size))) {<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial Narrow",sans-serif'> printf("Failed to write to SDO channel.\n");<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial Narrow",sans-serif'> }<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial Narrow",sans-serif'> ecrt_sdo_request_write(sdo); // trigger next read<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial Narrow",sans-serif'> break;<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial Narrow",sans-serif'> case EC_REQUEST_ERROR:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial Narrow",sans-serif'> fprintf(stderr, "Failed to write to SDO channel!\n");<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial Narrow",sans-serif'> ecrt_sdo_request_write(sdo); // retry reading<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial Narrow",sans-serif'> break;<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial Narrow",sans-serif'> }<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial Narrow",sans-serif'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial Narrow",sans-serif'> return sdo_write_ret;<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial Narrow",sans-serif'>}<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial Narrow",sans-serif'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>When compiling I get an </span><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black;background:red;mso-highlight:red'>undefined reference to `ec_sdo_request_copy_data'</span><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> error. I tried adding<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>EXPORT_SYMBOL(ec_sdo_request_copy_data);<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>at the end of /master/sdo_request.c and rebuild the master, but it didn’t help.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>It would be great if someone could help with this issue.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>Best Regards,<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>Ali<o:p></o:p></span></p></div></div></body></html>