SOEM/doc/html/tutorial_8txt.html
2014-11-25 16:10:29 +01:00

275 lines
28 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.3.1"/>
<title>SOEM: tutorial.txt File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td style="padding-left: 0.5em;">
<div id="projectname">SOEM
&#160;<span id="projectnumber">v1.3.0</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.3.1 -->
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main&#160;Page</span></a></li>
<li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
<li class="current"><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
<div id="navrow2" class="tabs2">
<ul class="tablist">
<li><a href="files.html"><span>File&#160;List</span></a></li>
<li><a href="globals.html"><span>Globals</span></a></li>
</ul>
</div>
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">tutorial.txt File Reference</div> </div>
</div><!--header-->
<div class="contents">
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><h1><a class="anchor" id="general"></a>
General</h1>
<p>The SOEM is a library that provides the user application with the means to send and receive EtherCAT frames. It is up to the application to provide means for:</p>
<ul>
<li>Reading and writing process data to be sent/received by SOEM</li>
<li>Keeping local IO data synchronised with the global IOmap</li>
<li>Detecting errors reported by SOEM</li>
<li>Managing errors reported by SOEM</li>
</ul>
<p>The following sections show some basic examples on how to get the SOEM up and running, as well as making use of the process data and checking for errors. Since all code is local to the application or global variables, it is possible to tweak and optimize when possible.</p>
<p>The following example shows how to add a main function that will be called by startup code. In this example main's only purpose is to spawn a new task that executes SOEM.</p>
<div class="fragment"><div class="line"><span class="keywordtype">int</span> <a class="code" href="ebox_8c.html#a0ddf1224851353fc92bfbff6f499fa97">main</a> (<span class="keywordtype">void</span>)</div>
<div class="line">{</div>
<div class="line"> rprintp(<span class="stringliteral">&quot;SOEM (Simple Open EtherCAT Master)\nSimple test\n&quot;</span>);</div>
<div class="line"></div>
<div class="line"> task_spawn (<span class="stringliteral">&quot;simpletest&quot;</span>, <a class="code" href="simple__test_8c.html#a97c8cfa2374fc882f9ce995d806a8dbb">simpletest</a>, 9, 8192, NULL);</div>
</div><!-- fragment --><h1><a class="anchor" id="configuration"></a>
Configuration</h1>
<p>Followed by start of the application we need to set up the NIC to be used as EtherCAT Ethernet interface. In a simple setup we call ec_init(ifname) and if SOEM comes with support for cable redundancy we call ec_init_redundant that will open a second port as backup. You can send NULL as ifname if you have a dedicated NIC selected in the nicdrv.c. It returns &gt;0 if succeeded.</p>
<div class="fragment"><div class="line"><span class="comment">/* initialise SOEM, bind socket to ifname */</span></div>
<div class="line"><span class="keywordflow">if</span> (<a class="code" href="ethercatmain_8c.html#a4d4ce1bfe67dcda4868fe1717af993af">ec_init</a>(ifname))</div>
</div><!-- fragment --><p>SOEM is a light weight ethercat master library used in embedded systems, It supports only runtime configuration. It requests a BRD (Broad Cast Read) of address 0, all fully functional slaves in the network will respond to this request, and therefore we will get a working counter equal to the number of slaves in the network. ec_config_init also sets up the mailboxes for slaves that support it. When ec_config_init finishes it will have requested all slaves to state PRE_OP. All data read and configured are stored in a global array which acts as a placeholder for key values, consult ec_slave for detailed information. </p>
<div class="fragment"><div class="line"><span class="comment">/* find and auto-config slaves */</span></div>
<div class="line"><span class="keywordflow">if</span> ( <a class="code" href="ethercatconfig_8c.html#ae9128b2cb982fd03fae9105d746f8656">ec_config_init</a>(FALSE) &gt; 0 )</div>
<div class="line">{</div>
<div class="line"> rprintp(<span class="stringliteral">&quot;%d slaves found and configured.\n&quot;</span>,<a class="code" href="ethercatmain_8c.html#aa9c784abc9a4ede41d3d8d688b4a7dc5">ec_slavecount</a>);</div>
</div><!-- fragment --><p>SOEM has now discovered and configured the network it is connected to. Now we can verify that all slaves are present as expected. These definitions could be generated by an external tool in an offline .h file. The definitions could be replaced by a struct keeping slave number.</p>
<div class="fragment"><div class="line"><span class="preprocessor">#define EK1100_1 1</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define EL4001_1 2</span></div>
<div class="line"><span class="preprocessor"></span>...</div>
<div class="line">#define EL2622_3 8</div>
<div class="line"><span class="preprocessor">#define EL2622_4 9</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define NUMBER_OF_SLAVES 9</span></div>
<div class="line"><span class="preprocessor"></span></div>
<div class="line">snippet</div>
<div class="line">...</div>
<div class="line"></div>
<div class="line">uint32 network_configuration(<span class="keywordtype">void</span>)</div>
<div class="line">{</div>
<div class="line"> <span class="comment">/* Do we got expected number of slaves from config */</span></div>
<div class="line"> <span class="keywordflow">if</span> (<a class="code" href="ethercatmain_8c.html#aa9c784abc9a4ede41d3d8d688b4a7dc5">ec_slavecount</a> &lt; NUMBER_OF_SLAVES)</div>
<div class="line"> <span class="keywordflow">return</span> 0;</div>
<div class="line"></div>
<div class="line"> <span class="comment">/* Verify slave by slave that it is correct*/</span></div>
<div class="line"> <span class="keywordflow">if</span> (strcmp(<a class="code" href="ethercatmain_8c.html#a309bc1e26d5c2ce80d69804b30bbb6a7">ec_slave</a>[EK1100_1].name,<span class="stringliteral">&quot;EK1100&quot;</span>))</div>
<div class="line"> <span class="keywordflow">return</span> 0;</div>
<div class="line"> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(<a class="code" href="ethercatmain_8c.html#a309bc1e26d5c2ce80d69804b30bbb6a7">ec_slave</a>[EL4001_1].name,<span class="stringliteral">&quot;EL4001&quot;</span>))</div>
<div class="line"> <span class="keywordflow">return</span> 0;</div>
<div class="line">...</div>
<div class="line"> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(<a class="code" href="ethercatmain_8c.html#a309bc1e26d5c2ce80d69804b30bbb6a7">ec_slave</a>[EL2622_4].name,<span class="stringliteral">&quot;EL2622&quot;</span>))</div>
<div class="line"> <span class="keywordflow">return</span> 0;</div>
<div class="line"></div>
<div class="line"> <span class="keywordflow">return</span> 1;</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><a class="code" href="simple__test_8c.html#a97c8cfa2374fc882f9ce995d806a8dbb">simpletest</a></div>
<div class="line">...</div>
<div class="line"> <span class="keywordflow">if</span> (network_configuration())</div>
<div class="line"> ...</div>
<div class="line"> <span class="keywordflow">else</span></div>
<div class="line"> rprintp(<span class="stringliteral">&quot;Mismatch of network units!\n&quot;</span>); </div>
</div><!-- fragment --><p>We now have the network up and configured. Mailboxes are up for slaves that support it. Next we will create an IOmap and configure the SyncManager's and FMMU's to link the EtherCAT master and the slaves. The IO mapping is done automatically, SOEM strives to keep the logical process image as compact as possible. It is done by trying to fit Bit oriented slaves together in single bytes. Below is an example of 8 slaves and how they are ordered. During mapping SOEM also calculates an expected WKC for the IO mapped together. That is the primary key to detect errors.</p>
<ul>
<li>Outputs are placed together in the beginning of the IOmap</li>
<li>Inputs follow</li>
</ul>
<p>When the mapping is done SOEM requests slaves to enter SAFE_OP.</p>
<div class="fragment"><div class="line"><span class="keywordtype">char</span> <a class="code" href="ebox_8c.html#abd49ea7d1a34c36e74ff633f727a6260">IOmap</a>[128];</div>
<div class="line">...</div>
<div class="line"> <a class="code" href="ethercatconfig_8c.html#aa740a2ba948117670c4f9741bc31cc38">ec_config_map</a>(&amp;IOmap);</div>
<div class="line">...</div>
</div><!-- fragment --><div class="image">
<img src="memory_layout.png" alt="memory_layout.png"/>
<div class="caption">
memory layout, mapping between physical and logical</div></div>
<p>To enter state OP we need to send valid data to outputs. The EtherCAT frame handling is split into ec_send_processdata and ec_receive_processdata.</p>
<ul>
<li>ec_send_processdata sends the frame on the NIC and saves the frame on the stack for receive to fetch.</li>
<li>ec_receive_processdata(EC_TIMEOUTRET) tries to fetch the frames on the stack. We send an argument for how long we will try to fetch the frame. ec_receive_processdata returns the working counter.</li>
</ul>
<div class="fragment"><div class="line"> <span class="comment">/* send one valid process data to make outputs in slaves happy*/</span></div>
<div class="line"> <a class="code" href="ethercatmain_8c.html#a30c66bb9d54e741149f7d40bbdb21078">ec_send_processdata</a>();</div>
<div class="line"> <a class="code" href="eepromtool_8c.html#aa59bf150c9e0d285619f7c7e58c9942d">wkc</a> = <a class="code" href="ethercatmain_8c.html#a14280050ace4427d196acd17e6d79e55">ec_receive_processdata</a>(<a class="code" href="ethercattype_8h.html#a334e41422731fd6d427d2a7ec790779c">EC_TIMEOUTRET</a>);</div>
<div class="line">...</div>
<div class="line"> <a class="code" href="ethercatmain_8c.html#a0750885eaa4230b7815a84ce8d627984">ec_writestate</a>(0);</div>
<div class="line"> <span class="comment">/* wait for all slaves to reach OP state */</span></div>
<div class="line"> <a class="code" href="ethercatmain_8c.html#a8f77918c0a6a32be1079a11119171901">ec_statecheck</a>(0, <a class="code" href="ethercattype_8h.html#ac93847b4c4f8ff2d123e3717d55358c1a53b0bd865c4b3b88652d26e67d66b1cb">EC_STATE_OPERATIONAL</a>, <a class="code" href="ethercattype_8h.html#ad62eda81b3771cefb501543b184d64ad">EC_TIMEOUTSTATE</a>);</div>
</div><!-- fragment --><ul>
<li>Now we have a system up and running, all slaves are in state operational.</li>
</ul>
<h1><a class="anchor" id="application"></a>
Application</h1>
<p>IO data is accessed through the IOmap, the ec_slave struct keep pointers to the start byte in the IO map on slave level together with start bit within the start byte. This way we can bit mask IO on bit level even though SOEM has combined slave data to minimize the frame size to be sent. We'll use slave 8 in the picture above as an example. From a printout from ec_slave we have the following:</p>
<ul>
<li>Slave:8<ul>
<li>Name:EL2622</li>
<li>Output size: 2bits</li>
<li>Input size: 0bits</li>
<li>Configured address: 1008</li>
<li>Outputs address: 18cf6</li>
<li>Inputs address: 0</li>
<li>FMMU0 Ls:2 Ll: 1 Lsb:4 Leb:5 Ps:f00 Psb:0 Ty:2 Act:1</li>
</ul>
</li>
</ul>
<p>The Outputs address: 18cf6 is the pointer to slave 8's start byte. The FMMU's Lsb:4 (LogicalStartBit) = ec_slave.Ostartbit telling us how to mask for the individual bits in the combined byte. The same goes for byte addressed slaves, but byte slaves only need the byte start address since they are byte aligned, the start bit will be 0.</p>
<p>Some example on how to access different types of data</p>
<p>Set an output int 16 value when memory alignment needs to be considered, arguments is:</p>
<ul>
<li>slave number in ethercat network</li>
<li>module index as index internal to the slave in case more than one channel</li>
<li>value to write</li>
</ul>
<div class="fragment"><div class="line"><span class="preprocessor">#define EL4001_1 2</span></div>
<div class="line"><span class="preprocessor"></span>...</div>
<div class="line">void set_output_int16 (uint16 slave_no, uint8 module_index, int16 value)</div>
<div class="line">{</div>
<div class="line"> uint8 *data_ptr;</div>
<div class="line"></div>
<div class="line"> data_ptr = <a class="code" href="ethercatmain_8c.html#a309bc1e26d5c2ce80d69804b30bbb6a7">ec_slave</a>[slave_no].<a class="code" href="structec__slavet.html#adf6bd2b568de0c34fa9a2a10af521ab2">outputs</a>;</div>
<div class="line"> <span class="comment">/* Move pointer to correct module index*/</span></div>
<div class="line"> data_ptr += module_index * 2;</div>
<div class="line"> <span class="comment">/* Read value byte by byte since all targets can&#39;t handle misaligned</span></div>
<div class="line"><span class="comment"> addresses</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"> *data_ptr++ = (value &gt;&gt; 0) &amp; 0xFF;</div>
<div class="line"> *data_ptr++ = (value &gt;&gt; 8) &amp; 0xFF;</div>
<div class="line">}</div>
<div class="line">...</div>
<div class="line">set_output_int16(EL4001_1,0,slave_EL4001_1.out1);</div>
</div><!-- fragment --><p>Target can handle non aligned pointers to the IOmap </p>
<div class="fragment"><div class="line"><span class="keyword">typedef</span> <span class="keyword">struct </span>PACKED</div>
<div class="line">{</div>
<div class="line"> int16 outvalue1;</div>
<div class="line"> int16 outvalue2;</div>
<div class="line">} out_EL4132t;</div>
<div class="line"></div>
<div class="line">out_EL4132t *out_EL4132;</div>
<div class="line">...</div>
<div class="line"> <span class="comment">/* connect struct pointers to slave I/O pointers */</span></div>
<div class="line"> out_EL4132 = (out_EL4132t*) <a class="code" href="ethercatmain_8c.html#a309bc1e26d5c2ce80d69804b30bbb6a7">ec_slave</a>[3].outputs;</div>
<div class="line"> out_EL4132-&gt;outvalue2 = 0x3FFF;</div>
<div class="line"> </div>
<div class="line">... </div>
</div><!-- fragment --><p>Identify and manage errors. The key is the Working Counter, CRC errors and errors local to the slave causing a state change can be detected by loss of Working Counter since the syncmanagers won't get updated. When returning Working Counter don't match Expected Working Counter something is wrong, then it is up to an error handler to act, locate the erroneous slave and decide what action to perform. The error may not be fatal. Some basic code from simple_test. </p>
<div class="fragment"><div class="line"><a class="code" href="eepromtool_8c.html#aa59bf150c9e0d285619f7c7e58c9942d">wkc</a> = <a class="code" href="ethercatmain_8c.html#a14280050ace4427d196acd17e6d79e55">ec_receive_processdata</a>(<a class="code" href="ethercattype_8h.html#a334e41422731fd6d427d2a7ec790779c">EC_TIMEOUTRET</a>);</div>
<div class="line"><a class="code" href="red__test_8c.html#ab60b608e97ebe19c7eba7d0cfcdd6fc0">expectedWKC</a> = (<a class="code" href="ethercatmain_8c.html#a2bdce50a46e56597354e404a55344934">ec_group</a>[0].<a class="code" href="structec__groupt.html#a96a49c502e4b1f51eab6f28dd3a92823">outputsWKC</a> * 2) + <a class="code" href="ethercatmain_8c.html#a2bdce50a46e56597354e404a55344934">ec_group</a>[0].inputsWKC;</div>
<div class="line"></div>
<div class="line"><span class="keywordflow">if</span>( <a class="code" href="red__test_8c.html#aaf1ab5178db6176b2175a1697ebe3ee8">inOP</a> &amp;&amp; ((<a class="code" href="eepromtool_8c.html#aa59bf150c9e0d285619f7c7e58c9942d">wkc</a> &lt; <a class="code" href="red__test_8c.html#ab60b608e97ebe19c7eba7d0cfcdd6fc0">expectedWKC</a>) || <a class="code" href="ethercatmain_8c.html#a2bdce50a46e56597354e404a55344934">ec_group</a>[<a class="code" href="red__test_8c.html#ab70420f3258d99639f12667adc46ac1a">currentgroup</a>].docheckstate))</div>
<div class="line">{</div>
<div class="line"> <span class="keywordflow">if</span> (<a class="code" href="red__test_8c.html#a902cd563ff7e274d2902d62fe1f575de">needlf</a>)</div>
<div class="line"> {</div>
<div class="line"> <a class="code" href="red__test_8c.html#a902cd563ff7e274d2902d62fe1f575de">needlf</a> = FALSE;</div>
<div class="line"> printf(<span class="stringliteral">&quot;\n&quot;</span>);</div>
<div class="line"> }</div>
<div class="line"> <span class="comment">/* one ore more slaves are not responding */</span></div>
<div class="line"> <a class="code" href="ethercatmain_8c.html#a2bdce50a46e56597354e404a55344934">ec_group</a>[<a class="code" href="red__test_8c.html#ab70420f3258d99639f12667adc46ac1a">currentgroup</a>].<a class="code" href="structec__groupt.html#a14723e0a5dec5ac026da07c1a141e9e4">docheckstate</a> = FALSE;</div>
<div class="line"> <a class="code" href="ethercatmain_8c.html#a585d9cd831f1d43f1bbaf7a50ee9759c">ec_readstate</a>();</div>
<div class="line"> <span class="keywordflow">for</span> (<a class="code" href="eepromtool_8c.html#a7f46665d1fe6d01a75a90942bb34cfaf">slave</a> = 1; <a class="code" href="eepromtool_8c.html#a7f46665d1fe6d01a75a90942bb34cfaf">slave</a> &lt;= <a class="code" href="ethercatmain_8c.html#aa9c784abc9a4ede41d3d8d688b4a7dc5">ec_slavecount</a>; <a class="code" href="eepromtool_8c.html#a7f46665d1fe6d01a75a90942bb34cfaf">slave</a>++)</div>
<div class="line"> {</div>
<div class="line"> <span class="keywordflow">if</span> ((<a class="code" href="ethercatmain_8c.html#a309bc1e26d5c2ce80d69804b30bbb6a7">ec_slave</a>[<a class="code" href="eepromtool_8c.html#a7f46665d1fe6d01a75a90942bb34cfaf">slave</a>].group == <a class="code" href="red__test_8c.html#ab70420f3258d99639f12667adc46ac1a">currentgroup</a>) &amp;&amp; (<a class="code" href="ethercatmain_8c.html#a309bc1e26d5c2ce80d69804b30bbb6a7">ec_slave</a>[<a class="code" href="eepromtool_8c.html#a7f46665d1fe6d01a75a90942bb34cfaf">slave</a>].state != <a class="code" href="ethercattype_8h.html#ac93847b4c4f8ff2d123e3717d55358c1a53b0bd865c4b3b88652d26e67d66b1cb">EC_STATE_OPERATIONAL</a>))</div>
<div class="line"> {</div>
<div class="line"> <a class="code" href="ethercatmain_8c.html#a2bdce50a46e56597354e404a55344934">ec_group</a>[<a class="code" href="red__test_8c.html#ab70420f3258d99639f12667adc46ac1a">currentgroup</a>].<a class="code" href="structec__groupt.html#a14723e0a5dec5ac026da07c1a141e9e4">docheckstate</a> = TRUE;</div>
<div class="line"> <span class="keywordflow">if</span> (<a class="code" href="ethercatmain_8c.html#a309bc1e26d5c2ce80d69804b30bbb6a7">ec_slave</a>[<a class="code" href="eepromtool_8c.html#a7f46665d1fe6d01a75a90942bb34cfaf">slave</a>].state == (<a class="code" href="ethercattype_8h.html#ac93847b4c4f8ff2d123e3717d55358c1acc09f39d0638c3b71e56b3614170810d">EC_STATE_SAFE_OP</a> + <a class="code" href="ethercattype_8h.html#ac93847b4c4f8ff2d123e3717d55358c1a421cd7b4c1e9a5e4a21991ef470c00dc">EC_STATE_ERROR</a>))</div>
<div class="line"> {</div>
<div class="line"> printf(<span class="stringliteral">&quot;ERROR : slave %d is in SAFE_OP + ERROR, attempting ack.\n&quot;</span>, <a class="code" href="eepromtool_8c.html#a7f46665d1fe6d01a75a90942bb34cfaf">slave</a>);</div>
<div class="line"> <a class="code" href="ethercatmain_8c.html#a309bc1e26d5c2ce80d69804b30bbb6a7">ec_slave</a>[<a class="code" href="eepromtool_8c.html#a7f46665d1fe6d01a75a90942bb34cfaf">slave</a>].<a class="code" href="structec__slavet.html#a676698529966da16de36d4dcb94473af">state</a> = (<a class="code" href="ethercattype_8h.html#ac93847b4c4f8ff2d123e3717d55358c1acc09f39d0638c3b71e56b3614170810d">EC_STATE_SAFE_OP</a> + <a class="code" href="ethercattype_8h.html#ac93847b4c4f8ff2d123e3717d55358c1a5c592a738e13641d3c8195d172f8c077">EC_STATE_ACK</a>);</div>
<div class="line"> <a class="code" href="ethercatmain_8c.html#a0750885eaa4230b7815a84ce8d627984">ec_writestate</a>(<a class="code" href="eepromtool_8c.html#a7f46665d1fe6d01a75a90942bb34cfaf">slave</a>);</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">else</span> <span class="keywordflow">if</span>(<a class="code" href="ethercatmain_8c.html#a309bc1e26d5c2ce80d69804b30bbb6a7">ec_slave</a>[<a class="code" href="eepromtool_8c.html#a7f46665d1fe6d01a75a90942bb34cfaf">slave</a>].state == <a class="code" href="ethercattype_8h.html#ac93847b4c4f8ff2d123e3717d55358c1acc09f39d0638c3b71e56b3614170810d">EC_STATE_SAFE_OP</a>)</div>
<div class="line"> {</div>
<div class="line"> printf(<span class="stringliteral">&quot;WARNING : slave %d is in SAFE_OP, change to OPERATIONAL.\n&quot;</span>, <a class="code" href="eepromtool_8c.html#a7f46665d1fe6d01a75a90942bb34cfaf">slave</a>);</div>
<div class="line"> <a class="code" href="ethercatmain_8c.html#a309bc1e26d5c2ce80d69804b30bbb6a7">ec_slave</a>[<a class="code" href="eepromtool_8c.html#a7f46665d1fe6d01a75a90942bb34cfaf">slave</a>].<a class="code" href="structec__slavet.html#a676698529966da16de36d4dcb94473af">state</a> = <a class="code" href="ethercattype_8h.html#ac93847b4c4f8ff2d123e3717d55358c1a53b0bd865c4b3b88652d26e67d66b1cb">EC_STATE_OPERATIONAL</a>;</div>
<div class="line"> <a class="code" href="ethercatmain_8c.html#a0750885eaa4230b7815a84ce8d627984">ec_writestate</a>(<a class="code" href="eepromtool_8c.html#a7f46665d1fe6d01a75a90942bb34cfaf">slave</a>); </div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">else</span> <span class="keywordflow">if</span>(<a class="code" href="ethercatmain_8c.html#a309bc1e26d5c2ce80d69804b30bbb6a7">ec_slave</a>[<a class="code" href="eepromtool_8c.html#a7f46665d1fe6d01a75a90942bb34cfaf">slave</a>].state &gt; 0)</div>
<div class="line"> { </div>
<div class="line"> <span class="keywordflow">if</span> (<a class="code" href="ethercatconfig_8c.html#aad37ae196ac8cc233dcae740f9fd4864">ec_reconfig_slave</a>(<a class="code" href="eepromtool_8c.html#a7f46665d1fe6d01a75a90942bb34cfaf">slave</a>, <a class="code" href="red__test_8c.html#a984397379b1b2255a13470ac600ae679">EC_TIMEOUTMON</a>))</div>
<div class="line"> {</div>
<div class="line"> <a class="code" href="ethercatmain_8c.html#a309bc1e26d5c2ce80d69804b30bbb6a7">ec_slave</a>[<a class="code" href="eepromtool_8c.html#a7f46665d1fe6d01a75a90942bb34cfaf">slave</a>].<a class="code" href="structec__slavet.html#a80d6b5ae9aeeacc8e75c5395c09b52f6">islost</a> = FALSE;</div>
<div class="line"> printf(<span class="stringliteral">&quot;MESSAGE : slave %d reconfigured\n&quot;</span>,<a class="code" href="eepromtool_8c.html#a7f46665d1fe6d01a75a90942bb34cfaf">slave</a>); </div>
<div class="line"> }</div>
<div class="line"> } </div>
<div class="line"> <span class="keywordflow">else</span> <span class="keywordflow">if</span>(!<a class="code" href="ethercatmain_8c.html#a309bc1e26d5c2ce80d69804b30bbb6a7">ec_slave</a>[<a class="code" href="eepromtool_8c.html#a7f46665d1fe6d01a75a90942bb34cfaf">slave</a>].islost)</div>
<div class="line"> {</div>
<div class="line"> <span class="comment">/* re-check state */</span></div>
<div class="line"> <a class="code" href="ethercatmain_8c.html#a8f77918c0a6a32be1079a11119171901">ec_statecheck</a>(<a class="code" href="eepromtool_8c.html#a7f46665d1fe6d01a75a90942bb34cfaf">slave</a>, <a class="code" href="ethercattype_8h.html#ac93847b4c4f8ff2d123e3717d55358c1a53b0bd865c4b3b88652d26e67d66b1cb">EC_STATE_OPERATIONAL</a>, <a class="code" href="ethercattype_8h.html#a334e41422731fd6d427d2a7ec790779c">EC_TIMEOUTRET</a>);</div>
<div class="line"> <span class="keywordflow">if</span> (!<a class="code" href="ethercatmain_8c.html#a309bc1e26d5c2ce80d69804b30bbb6a7">ec_slave</a>[<a class="code" href="eepromtool_8c.html#a7f46665d1fe6d01a75a90942bb34cfaf">slave</a>].state)</div>
<div class="line"> {</div>
<div class="line"> <a class="code" href="ethercatmain_8c.html#a309bc1e26d5c2ce80d69804b30bbb6a7">ec_slave</a>[<a class="code" href="eepromtool_8c.html#a7f46665d1fe6d01a75a90942bb34cfaf">slave</a>].<a class="code" href="structec__slavet.html#a80d6b5ae9aeeacc8e75c5395c09b52f6">islost</a> = TRUE;</div>
<div class="line"> printf(<span class="stringliteral">&quot;ERROR : slave %d lost\n&quot;</span>,<a class="code" href="eepromtool_8c.html#a7f46665d1fe6d01a75a90942bb34cfaf">slave</a>); </div>
<div class="line"> }</div>
<div class="line"> }</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">if</span> (<a class="code" href="ethercatmain_8c.html#a309bc1e26d5c2ce80d69804b30bbb6a7">ec_slave</a>[<a class="code" href="eepromtool_8c.html#a7f46665d1fe6d01a75a90942bb34cfaf">slave</a>].islost)</div>
<div class="line"> {</div>
<div class="line"> <span class="keywordflow">if</span>(!<a class="code" href="ethercatmain_8c.html#a309bc1e26d5c2ce80d69804b30bbb6a7">ec_slave</a>[<a class="code" href="eepromtool_8c.html#a7f46665d1fe6d01a75a90942bb34cfaf">slave</a>].state)</div>
<div class="line"> {</div>
<div class="line"> <span class="keywordflow">if</span> (<a class="code" href="ethercatconfig_8c.html#aa31ccd813ba490a3c0e6d57315e42606">ec_recover_slave</a>(<a class="code" href="eepromtool_8c.html#a7f46665d1fe6d01a75a90942bb34cfaf">slave</a>, <a class="code" href="red__test_8c.html#a984397379b1b2255a13470ac600ae679">EC_TIMEOUTMON</a>))</div>
<div class="line"> {</div>
<div class="line"> <a class="code" href="ethercatmain_8c.html#a309bc1e26d5c2ce80d69804b30bbb6a7">ec_slave</a>[<a class="code" href="eepromtool_8c.html#a7f46665d1fe6d01a75a90942bb34cfaf">slave</a>].<a class="code" href="structec__slavet.html#a80d6b5ae9aeeacc8e75c5395c09b52f6">islost</a> = FALSE;</div>
<div class="line"> printf(<span class="stringliteral">&quot;MESSAGE : slave %d recovered\n&quot;</span>,<a class="code" href="eepromtool_8c.html#a7f46665d1fe6d01a75a90942bb34cfaf">slave</a>); </div>
<div class="line"> }</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">else</span></div>
<div class="line"> {</div>
<div class="line"> <a class="code" href="ethercatmain_8c.html#a309bc1e26d5c2ce80d69804b30bbb6a7">ec_slave</a>[<a class="code" href="eepromtool_8c.html#a7f46665d1fe6d01a75a90942bb34cfaf">slave</a>].<a class="code" href="structec__slavet.html#a80d6b5ae9aeeacc8e75c5395c09b52f6">islost</a> = FALSE;</div>
<div class="line"> printf(<span class="stringliteral">&quot;MESSAGE : slave %d found\n&quot;</span>,<a class="code" href="eepromtool_8c.html#a7f46665d1fe6d01a75a90942bb34cfaf">slave</a>); </div>
<div class="line"> }</div>
<div class="line"> }</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">if</span>(!<a class="code" href="ethercatmain_8c.html#a2bdce50a46e56597354e404a55344934">ec_group</a>[<a class="code" href="red__test_8c.html#ab70420f3258d99639f12667adc46ac1a">currentgroup</a>].docheckstate)</div>
<div class="line"> printf(<span class="stringliteral">&quot;OK : all slaves resumed OPERATIONAL.\n&quot;</span>);</div>
<div class="line">} </div>
</div><!-- fragment --><p>This tutorial is just one way of doing it. Enjoy and happy coding!</p>
<p>Andreas Karlsson, rt-labs AB, www.rt-labs.com </p>
</div></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Tue Feb 26 2013 13:57:51 for SOEM by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.3.1
</small></address>
</body>
</html>