<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 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 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;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
{mso-style-priority:99;
mso-style-link:"Balloon Text Char";
margin:0cm;
margin-bottom:.0001pt;
font-size:8.0pt;
font-family:"Tahoma","sans-serif";
mso-fareast-language:EN-US;}
span.EmailStyle17
{mso-style-type:personal;
font-family:"Calibri","sans-serif";
color:windowtext;}
span.EmailStyle18
{mso-style-type:personal;
font-family:"Calibri","sans-serif";
color:#1F497D;}
span.EmailStyle19
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
span.BalloonTextChar
{mso-style-name:"Balloon Text Char";
mso-style-priority:99;
mso-style-link:"Balloon Text";
font-family:"Tahoma","sans-serif";
mso-fareast-language:EN-US;}
.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-GB" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="color:#1F497D">Hi Ali,<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">Have you read sdos successfully already? Are you writing code using user space or in kernel space? Are you using a cyclic task?<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">What is the purpose of <o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">ec_sdo_request_copy_data(sdo_server, data, size)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">on success?<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">Are you attempting to read at the end of a successful write?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">That is not really “writing” functionality.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">ec_sdo_request_copy_data is not part of the user space API and the symbol shows on the master side of the code only.<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">HTH.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">Ronaldo<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"><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 #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif";mso-fareast-language:EN-GB">From:</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif";mso-fareast-language:EN-GB"> etherlab-users
[mailto:etherlab-users-bounces@etherlab.org] <b>On Behalf Of </b>Gavin Lambert<br>
<b>Sent:</b> 28 July 2015 02:22<br>
<b>To:</b> 'HASSAN ZAHRAEE Ali'<br>
<b>Cc:</b> etherlab-users@etherlab.org<br>
<b>Subject:</b> Re: [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="EN-NZ" 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 lang="EN-NZ" style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-NZ" 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 lang="EN-US" style="color:#1F497D">
</span><span lang="EN-NZ" 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 lang="EN-NZ" style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-NZ" 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 lang="EN-NZ" style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-NZ" 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 lang="EN-NZ" 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 [<a href="mailto:etherlab-users-bounces@etherlab.org">mailto:etherlab-users-bounces@etherlab.org</a>]
<b>On Behalf Of </b>HASSAN ZAHRAEE Ali<br>
<b>Sent:</b> Tuesday, 28 July 2015 03:47<br>
<b>To:</b> <a href="mailto:etherlab-users@etherlab.org">etherlab-users@etherlab.org</a><br>
<b>Subject:</b> [etherlab-users] write_sdo() function<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><span lang="EN-NZ"><o:p> </o:p></span></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>
</div>
<p align="justify"> </p>
<p align="justify">-- </p>
<p align="justify">This e-mail and any attachments may contain confidential, copyright and or privileged material, and are for the use of the intended addressee only. If you are not the intended addressee or an authorised recipient of the addressee please notify us of receipt by returning the e-mail and do not use, copy, retain, distribute or disclose the information in or attached to the e-mail.<br />Any opinions expressed within this e-mail are those of the individual and not necessarily of Diamond Light Source Ltd. <br />Diamond Light Source Ltd. cannot guarantee that this e-mail or any attachments are free from viruses and we cannot accept liability for any damage which you may sustain as a result of software viruses which may be transmitted in or with the message.<br />Diamond Light Source Limited (company no. 4375679). Registered in England and Wales with its registered office at Diamond House, Harwell Science and Innovation Campus, Didcot, Oxfordshire, OX11 0DE, United Kingdom<br /> </p></body>
</html>