<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)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><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;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
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.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle21
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
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="mso-fareast-language:EN-US">Hi Gavin,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">I have attached an updated patch for the Mailbox Gateway Server.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">This fixes a problem where EoE communications get incorrectly gobbled by the Mailbox Gateway handler.  This occurred with an EL6614 EoE module which doesn't fill in the Mailbox Header station address
 when retrieving EoE mailbox data.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Graeme.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<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">From:</span></b><span lang="EN-US"> etherlab-dev <etherlab-dev-bounces@etherlab.org>
<b>On Behalf Of </b>Graeme Foot<br>
<b>Sent:</b> Saturday, 20 July 2019 12:58 AM<br>
<b>To:</b> Gavin Lambert <gavin.lambert@tomra.com>; etherlab-dev@etherlab.org<br>
<b>Subject:</b> Re: [etherlab-dev] EtherCAT Mailbox Gateway Server patch<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div id="divtagdefaultwrapper">
<p><span style="font-size:12.0pt;color:black">Hi Gavin,<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
<p><span style="font-size:12.0pt;color:black">Thanks for the feedback.  I've updated the gap subindex's to return 0x08000020 (Data cannot be read or stored).<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
<p><span style="font-size:12.0pt;color:black">I've updated 0x8nnn:04 to ask the slave it's modular device profile from 0x1000:00 if the slave supports CoE protocol.  If it does not it will now return 0.  Looking at my comments I did find the 0x1000:00 value,
 but then forgot about it.<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
<p><span style="font-size:12.0pt;color:black">Have attached the updated patch.<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
<p><span style="font-size:12.0pt;color:black">Cheers,<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black">Graeme.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
<div>
<div class="MsoNormal" align="center" style="text-align:center"><span style="font-size:12.0pt;color:black">
<hr size="2" width="98%" align="center">
</span></div>
<div id="divRplyFwdMsg">
<p class="MsoNormal"><b><span style="color:black">From:</span></b><span style="color:black"> Gavin Lambert <<a href="mailto:gavin.lambert@tomra.com">gavin.lambert@tomra.com</a>><br>
<b>Sent:</b> Friday, 19 July 2019 18:34<br>
<b>To:</b> Graeme Foot; <a href="mailto:etherlab-dev@etherlab.org">etherlab-dev@etherlab.org</a><br>
<b>Subject:</b> RE: EtherCAT Mailbox Gateway Server patch</span><span style="font-size:12.0pt;color:black">
<o:p></o:p></span></p>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black"> <o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p><span style="color:black">Sounds interesting.<o:p></o:p></span></p>
<p><span style="color:black"> <o:p></o:p></span></p>
<p><span style="color:black">To address one of your questions, standard slave behaviour is to report “subindex not existing” (0x11) only if the requested subindex is higher than the maximum subindex that exists.  When accessing a “gap” subindex for which no
 data is available, it reports “data cannot be read or stored” (0x18) instead.  (There’s a few other variations of errors for cases where data is written when read-only, or can only be read/written in a different AL state, etc.)<o:p></o:p></span></p>
<p><span style="color:black"> <o:p></o:p></span></p>
<p><span style="color:black">Also, a slave’s module profile should be readable from SDO 0x1000.  Most general-purpose modular devices will report 0x00001389 here (others will report something else, of course); it’s a mandatory object for any slave that supports
 CoE.<o:p></o:p></span></p>
<p><span style="color:black"> <o:p></o:p></span></p>
<p><span style="color:black"> <o:p></o:p></span></p>
<p><span style="color:black">And yes, I’m currently in the process of integrating and updating the patchset.  It’s nearly done, but I’ve hit a bit of a brick wall at present where due to a recent kernel patch (which appears to be in recent versions of 4.4+)
 the e1000e driver fails to recover from loss of link when using a motherboard-based adapter.  Frustratingly, it’s a code change outside of the e1000e driver itself which is affecting its operation – although it does appear to operate correctly when used with
 ec_generic.  The good news is that the igb driver appears to be unaffected.  I’m hoping to figure out a workaround before release, though if it takes much longer then I might just release it as-is.<o:p></o:p></span></p>
<p><span style="color:black"> <o:p></o:p></span></p>
<p><strong><span style="font-size:12.0pt;font-family:"Calibri",sans-serif;color:#595959">Gavin Lambert</span></strong><b><span style="font-size:12.0pt;color:#595959"><br>
</span></b><span style="font-size:12.0pt;color:#595959">Senior Software Developer<o:p></o:p></span></p>
<table class="MsoNormalTable" border="0" cellpadding="0">
<tbody>
<tr>
<td style="padding:.75pt .75pt .75pt .75pt"></td>
</tr>
</tbody>
</table>
<p><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:black"><img border="0" width="360" height="102" style="width:3.75in;height:1.0625in" id="_x0000_i1026" src="cid:image001.png@01D56314.FE457C00"><br>
<a href="http://www.compacsort.com"><span style="color:#0563C1;text-decoration:none"><img border="0" width="33" height="37" style="width:.3437in;height:.3854in" id="_x0000_i1027" src="cid:image002.png@01D56314.FE457C00" alt="TOMRA"></span></a><a href="https://www.facebook.com/Compacsort"><span style="color:#0563C1;text-decoration:none"><img border="0" width="35" height="37" style="width:.3645in;height:.3854in" id="_x0000_i1028" src="cid:image003.png@01D56314.FE457C00" alt="Facebook"></span></a><a href="https://www.linkedin.com/company/compac-sorting-equipment/"><span style="color:#0563C1;text-decoration:none"><img border="0" width="35" height="37" style="width:.3645in;height:.3854in" id="_x0000_i1029" src="cid:image004.png@01D56314.FE457C00" alt="Linkedin"></span></a><a href="https://vimeo.com/compacsort"><span style="color:#0563C1;text-decoration:none"><img border="0" width="37" height="37" style="width:.3854in;height:.3854in" id="_x0000_i1030" src="cid:image005.png@01D56314.FE457C00" alt="Youtube"></span></a><a href="https://twitter.com/compacsort"><span style="color:#0563C1;text-decoration:none"><img border="0" width="33" height="37" style="width:.3437in;height:.3854in" id="_x0000_i1031" src="cid:image006.png@01D56314.FE457C00" alt="twitter"></span></a><o:p></o:p></span></p>
<p><b><span style="font-size:9.0pt;color:#595959">COMPAC SORTING EQUIPMENT LTD</span></b><span style="font-size:9.0pt;color:#595959"> | 4 Henderson Pl | Onehunga | Auckland 1061 | New Zealand<br>
Switchboard: +64 96 34 00 88 | <a href="http://www.tomra.com"><span style="color:#0563C1">tomra.com</span></a>
<o:p></o:p></span></p>
<table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" style="border-collapse:collapse">
<tbody>
<tr>
<td valign="top" style="border-top:solid #595959 1.0pt;border-left:none;border-bottom:solid #595959 1.0pt;border-right:none;padding:0cm 0cm 0cm 0cm">
<p><span style="font-size:8.5pt;color:#595959">The information contained in this communication and any attachment is confidential and may be legally privileged. It should only be read by the person(s) to whom it is addressed. If you have received this communication
 in error, please notify the sender and delete the communication. <o:p></o:p></span></p>
</td>
</tr>
</tbody>
</table>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p><b><span lang="EN-US" style="color:black">From:</span></b><span lang="EN-US" style="color:black"> Graeme Foot <<a href="mailto:Graeme.Foot@touchcut.com">Graeme.Foot@touchcut.com</a>>
<br>
<b>Sent:</b> Friday, 19 July 2019 17:57<br>
<b>To:</b> <a href="mailto:etherlab-dev@etherlab.org">etherlab-dev@etherlab.org</a><br>
<b>Cc:</b> Gavin Lambert <<a href="mailto:gavin.lambert@tomra.com">gavin.lambert@tomra.com</a>><br>
<b>Subject:</b> EtherCAT Mailbox Gateway Server patch</span><span style="color:black"><o:p></o:p></span></p>
</div>
</div>
<p><span style="color:black"> <o:p></o:p></span></p>
<div id="divtagdefaultwrapper">
<div>
<p><span style="font-size:12.0pt;color:black">Hi,</span><span style="color:black"><o:p></o:p></span></p>
</div>
<div>
<p><span style="font-size:12.0pt;color:black"> </span><span style="color:black"><o:p></o:p></span></p>
</div>
<div>
<p><span style="font-size:12.0pt;color:black">I have attached a patch to implement an EtherCAT Mailbox Gateway server.  Florian you may be interested in this as it is on the EtherLab TODO list.</span><span style="color:black"><o:p></o:p></span></p>
</div>
<div>
<p><span style="font-size:12.0pt;color:black"> </span><span style="color:black"><o:p></o:p></span></p>
</div>
<div>
<p><span style="font-size:12.0pt;color:black">The server provides for UDP and up to 16 TCP connections.  The the UDP and TCP connections are not multi-threaded.</span><span style="color:black"><o:p></o:p></span></p>
</div>
<div>
<p><span style="font-size:12.0pt;color:black"> </span><span style="color:black"><o:p></o:p></span></p>
</div>
<div>
<p><span style="font-size:12.0pt;color:black">It is based on the specification:</span><span style="color:black"><o:p></o:p></span></p>
</div>
<div>
<p><span style="font-size:12.0pt;color:black"><a href="https://www.ethercat.org/memberarea/download/ETG8200_V1i0i0_G_R_MailboxGateway.pdf"><span style="color:#0563C1">https://www.ethercat.org/memberarea/download/ETG8200_V1i0i0_G_R_MailboxGateway.pdf</span></a></span><span style="color:black"><o:p></o:p></span></p>
</div>
<div>
<p><span style="font-size:12.0pt;color:black"> </span><span style="color:black"><o:p></o:p></span></p>
</div>
<div>
<p><span style="font-size:12.0pt;color:black">It is designed to be used with tools such as:</span><span style="color:black"><o:p></o:p></span></p>
</div>
<div>
<p><span style="font-size:12.0pt;color:black"><a href="https://download.beckhoff.com/download/document/automation/twinsafe/twinsafe_loader_en.pdf"><span style="color:#0563C1">https://download.beckhoff.com/download/document/automation/twinsafe/twinsafe_loader_en.pdf</span></a></span><span style="color:black"><o:p></o:p></span></p>
</div>
<div>
<p><span style="font-size:12.0pt;color:black"> </span><span style="color:black"><o:p></o:p></span></p>
</div>
<div>
<p><span style="font-size:12.0pt;color:black">Note: the TwinSAFE Loader is a new program that allows you to apply TwinSAFE programs to your TwinSAFE modules without having the modules connected to TwinCAT.  You are still required to use TwinCAT to create the
 safety programs.  Last I looked there was no download link for the TwinSAFE loader as it is new and Beckhoff are still deciding on licensing, but I got a copy from our local rep.</span><span style="color:black"><o:p></o:p></span></p>
</div>
<div>
<p><span style="font-size:12.0pt;color:black"> </span><span style="color:black"><o:p></o:p></span></p>
</div>
<div>
<p><span style="font-size:12.0pt;color:black"> </span><span style="color:black"><o:p></o:p></span></p>
</div>
<div>
<p><span style="font-size:12.0pt;color:black">The server is built on top of the GavinL Etherlab master patchset 20171108.  It integrates into the multiple mailbox protocol patches functionality.  Mailbox datagrams from the Mailbox Gateway server are recognized
 due to the Mailbox Header address not matching the datagram ADP address.</span><span style="color:black"><o:p></o:p></span></p>
</div>
<div>
<p><span style="font-size:12.0pt;color:black"> </span><span style="color:black"><o:p></o:p></span></p>
</div>
<div>
<p><span style="font-size:12.0pt;color:black">The server is a user space program named "ethercat_mbg" loosly based on the "ethercat" user space tool (MBG stands for Mailbox Gateway).  The program can be run as a foreground or background task depending on whether
 you want to run it temporarily or as a daemon.  There is no security incorporated into the protocol so the server will give full access to the slave mailboxes while it is running.  The mailbox gateway listens on port 0x88A4 (34980) should you want to firewall
 the port.</span><span style="color:black"><o:p></o:p></span></p>
</div>
<div>
<p><span style="font-size:12.0pt;color:black"> </span><span style="color:black"><o:p></o:p></span></p>
</div>
<div>
<p><span style="font-size:12.0pt;color:black"> </span><span style="color:black"><o:p></o:p></span></p>
</div>
<div>
<p><span style="font-size:12.0pt;color:black">The Mailbox Gateway protocol requires the EtherCAT master to provide a Master Object Dictionary as specified by ETG.5001.3 (Modular Device Profile Part 3: Fieldbus Gateway Profile Specifications), Annex A:</span><span style="color:black"><o:p></o:p></span></p>
</div>
<div>
<p><span style="font-size:12.0pt;color:black"><a href="https://www.ethercat.org/memberarea/download/ETG5001_3_V0i1i2_S_D_MDP_Gateways.pdf"><span style="color:#0563C1">https://www.ethercat.org/memberarea/download/ETG5001_3_V0i1i2_S_D_MDP_Gateways.pdf</span></a></span><span style="color:black"><o:p></o:p></span></p>
</div>
<div>
<p><span style="font-size:12.0pt;color:black"> </span><span style="color:black"><o:p></o:p></span></p>
</div>
<div>
<p><span style="font-size:12.0pt;color:black">I have implemented all of the optional items, along with A.2.1.3 Diagnosis Data (index 0xAnnn) which is supposed to be optional but seems to be required by the TwinSAFE loader.  I'm not massively happy with the
 master object dictionary function (ec_master_obj_dict()) as it is handling all of the index:subindex requests in the one function.  However it shouldn't really grow unless someone wants to implement the optional items.</span><span style="color:black"><o:p></o:p></span></p>
</div>
<div>
<p><span style="font-size:12.0pt;color:black"> </span><span style="color:black"><o:p></o:p></span></p>
</div>
<div>
<p><span style="font-size:12.0pt;color:black">A few things to note:</span><span style="color:black"><o:p></o:p></span></p>
</div>
<div>
<p><span style="font-size:12.0pt;color:black">1) Items 0x8nnn:02 and 0x8nnn:03 of the master object dictionary return 16 and 32 character fixed length strings (respectively) with the extra characters nulled out.  In theory you should be able to return the exact
 length of the string (as is done by slaves) but the TwinSAFE Loader program seems to require null terminated strings.  The 16 and 32 characters come from matching the returned data from TwinCAT.</span><span style="color:black"><o:p></o:p></span></p>
</div>
<div>
<p><span style="font-size:12.0pt;color:black">2) Item 0x8nnn:04 should return the slave Modular Device Profile.  This information is not available in the slaves SII or from any of the standard SDO indexes (should the slave support SDO access).  It only seems
 to be available from the slaves ESI xml files which the EtherLab master does not use.  I have hardcoded the standard simple slave Modular Device Profile number of 0x1389 (5001).</span><span style="color:black"><o:p></o:p></span></p>
</div>
<div>
<p><span style="font-size:12.0pt;color:black">3) Item 0x8nnn has a gap in the sub indexes.  At the moment if one of the unspecified sub indexes is requested (9 - 32) I am returning a Subindex does not exist error.  Does anyone know if this is correct, or whether
 I should return some other value?</span><span style="color:black"><o:p></o:p></span></p>
</div>
<div>
<p><span style="font-size:12.0pt;color:black"> </span><span style="color:black"><o:p></o:p></span></p>
</div>
<div>
<p><span style="font-size:12.0pt;color:black"> </span><span style="color:black"><o:p></o:p></span></p>
</div>
<div>
<p><span style="font-size:12.0pt;color:black">I have only tested ethercat_mbg with the TwinSAFE_Loader --list function so far.  It correctly lists an EL6910 TwinSAFE PLC module.  It also sucessfully interacts with slave mailboxes.  I have not done any further
 testing with the TwinSAFE_Loader yet as I have another project I need to spend some time on.</span><span style="color:black"><o:p></o:p></span></p>
</div>
<div>
<p><span style="font-size:12.0pt;color:black"> </span><span style="color:black"><o:p></o:p></span></p>
</div>
<p><span style="font-size:12.0pt;color:black">Gavin, I'm sending this patch now as it looks like you are working on updating your patchset.  I've added this patch as an optional feature (features/mailbox-gateway) with an --enable-mbg build option defaulting
 to true.  If more people see it as worthwhile it might be worth adding as a base patch.
</span><span style="color:black"><o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black"> <o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black"> <o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black">Regards,<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black"> <o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black">Graeme Foot<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black">Kinetic Engineering Design Ltd.<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black"> <o:p></o:p></span></p>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>