【米尔MYD-YG2LX开发板】在工控领域的应用-基于SOEM的EtherCAT主站
<div class='showpostmsg'><h1><b>前言</b></h1><p >本文介绍【米尔MYD-YG2LX开发板】在工控领域的应用</p>
<p >,实现基于SOEM的EtherCAT主站。开发环境基于WSL2.</p>
<h1 ><b>下载代码</b></h1>
<p >git clone <a href="https://github.com/OpenEtherCATsociety/SOEM"><u>https://github.com/OpenEtherCATsociety/SOEM</u></a></p>
<h1 ><b>PC端</b></h1>
<h2 ><b>编译</b></h2>
<p >cd SOEM/</p>
<p >export CC=gcc</p>
<p >mkdir build_pc</p>
<p >cd build_pc/</p>
<p > </p>
<p >cmake ..</p>
<div class="parsedown-markdown">
<p>lhj@lhj:~/SOEM/build_pc$ cmake ..</p>
<p >-- The C compiler identification is GNU 9.4.0</p>
<p >-- Check for working C compiler: /usr/bin/gcc</p>
<p >-- Check for working C compiler: /usr/bin/gcc -- works</p>
<p >-- Detecting C compiler ABI info</p>
<p >-- Detecting C compiler ABI info - done</p>
<p >-- Detecting C compile features</p>
<p >-- Detecting C compile features - done</p>
<p >-- OS is linux</p>
<p >-- LIB_DIR: lib</p>
<p >-- Configuring done</p>
<p >-- Generating done</p>
<p >-- Build files have been written to: /home/lhj/SOEM/build_pc</p>
<p >lhj@lhj:~/SOEM/build_pc$</p>
</div>
<p > </p>
<p >make</p>
<div class="parsedown-markdown">
<p>lhj@lhj:~/SOEM/build_pc$ make</p>
<p >Scanning dependencies of target soem</p>
<p >[ 4%] Building C object CMakeFiles/soem.dir/soem/ethercatbase.c.o</p>
<p >[ 9%] Building C object CMakeFiles/soem.dir/soem/ethercatcoe.c.o</p>
<p >[ 14%] Building C object CMakeFiles/soem.dir/soem/ethercatconfig.c.o</p>
<p >[ 19%] Building C object CMakeFiles/soem.dir/soem/ethercatdc.c.o</p>
<p >[ 23%] Building C object CMakeFiles/soem.dir/soem/ethercateoe.c.o</p>
<p >[ 28%] Building C object CMakeFiles/soem.dir/soem/ethercatfoe.c.o</p>
<p >[ 33%] Building C object CMakeFiles/soem.dir/soem/ethercatmain.c.o</p>
<p >[ 38%] Building C object CMakeFiles/soem.dir/soem/ethercatprint.c.o</p>
<p >[ 42%] Building C object CMakeFiles/soem.dir/soem/ethercatsoe.c.o</p>
<p >[ 47%] Building C object CMakeFiles/soem.dir/osal/linux/osal.c.o</p>
<p >[ 52%] Building C object CMakeFiles/soem.dir/oshw/linux/nicdrv.c.o</p>
<p >[ 57%] Building C object CMakeFiles/soem.dir/oshw/linux/oshw.c.o</p>
<p >[ 61%] Linking C static library libsoem.a</p>
<p >[ 61%] Built target soem</p>
<p >Scanning dependencies of target simple_ng</p>
<p >[ 66%] Building C object test/simple_ng/CMakeFiles/simple_ng.dir/simple_ng.c.o</p>
<p >[ 71%] Linking C executable simple_ng</p>
<p >[ 71%] Built target simple_ng</p>
<p >Scanning dependencies of target slaveinfo</p>
<p >[ 76%] Building C object test/linux/slaveinfo/CMakeFiles/slaveinfo.dir/slaveinfo.c.o</p>
<p >[ 80%] Linking C executable slaveinfo</p>
<p >[ 80%] Built target slaveinfo</p>
<p >Scanning dependencies of target eepromtool</p>
<p >[ 85%] Building C object test/linux/eepromtool/CMakeFiles/eepromtool.dir/eepromtool.c.o</p>
<p >[ 90%] Linking C executable eepromtool</p>
<p >[ 90%] Built target eepromtool</p>
<p >Scanning dependencies of target simple_test</p>
<p >[ 95%] Building C object test/linux/simple_test/CMakeFiles/simple_test.dir/simple_test.c.o</p>
<p > Linking C executable simple_test</p>
<p > Built target simple_test</p>
<p >lhj@lhj:~/SOEM/build_pc$</p>
</div>
<p > </p>
<h2 ><b>部署</b></h2>
<p>生成的文件如下</p>
<p>其中libsoem.a为库文件</p>
<p>test/linux/下的</p>
<p>simple_test,slaveinfo,eepromtool为测试Demo。</p>
<div class="parsedown-markdown">
<p>lhj@lhj:~/SOEM/build_pc$ tree .<br />
.<br />
|-- CMakeCache.txt<br />
|-- CMakeFiles<br />
| |-- 3.16.3<br />
| | |-- CMakeCCompiler.cmake<br />
| | |-- CMakeDetermineCompilerABI_C.bin<br />
| | |-- CMakeSystem.cmake<br />
| | `-- CompilerIdC<br />
| | |-- CMakeCCompilerId.c<br />
| | |-- a.out<br />
| | `-- tmp<br />
| |-- CMakeDirectoryInformation.cmake<br />
| |-- CMakeOutput.log<br />
| |-- CMakeTmp<br />
| |-- Export<br />
| | `-- share<br />
| | `-- soem<br />
| | `-- cmake<br />
| | |-- soemConfig-noconfig.cmake<br />
| | `-- soemConfig.cmake<br />
| |-- Makefile.cmake<br />
| |-- Makefile2<br />
| |-- TargetDirectories.txt<br />
| |-- cmake.check_cache<br />
| |-- progress.marks<br />
| `-- soem.dir<br />
| |-- C.includecache<br />
| |-- DependInfo.cmake<br />
| |-- build.make<br />
| |-- cmake_clean.cmake<br />
| |-- cmake_clean_target.cmake<br />
| |-- depend.internal<br />
| |-- depend.make<br />
| |-- flags.make<br />
| |-- link.txt<br />
| |-- osal<br />
| | `-- linux<br />
| | `-- osal.c.o<br />
| |-- oshw<br />
| | `-- linux<br />
| | |-- nicdrv.c.o<br />
| | `-- oshw.c.o<br />
| |-- progress.make<br />
| `-- soem<br />
| |-- ethercatbase.c.o<br />
| |-- ethercatcoe.c.o<br />
| |-- ethercatconfig.c.o<br />
| |-- ethercatdc.c.o<br />
| |-- ethercateoe.c.o<br />
| |-- ethercatfoe.c.o<br />
| |-- ethercatmain.c.o<br />
| |-- ethercatprint.c.o<br />
| `-- ethercatsoe.c.o<br />
|-- Makefile<br />
|-- cmake_install.cmake<br />
|-- libsoem.a<br />
`-- test<br />
|-- linux<br />
| |-- eepromtool<br />
| | |-- CMakeFiles<br />
| | | |-- CMakeDirectoryInformation.cmake<br />
| | | |-- eepromtool.dir<br />
| | | | |-- C.includecache<br />
| | | | |-- DependInfo.cmake<br />
| | | | |-- build.make<br />
| | | | |-- cmake_clean.cmake<br />
| | | | |-- depend.internal<br />
| | | | |-- depend.make<br />
| | | | |-- eepromtool.c.o<br />
| | | | |-- flags.make<br />
| | | | |-- link.txt<br />
| | | | `-- progress.make<br />
| | | `-- progress.marks<br />
| | |-- Makefile<br />
| | |-- cmake_install.cmake<br />
| | `-- eepromtool<br />
| |-- simple_test<br />
| | |-- CMakeFiles<br />
| | | |-- CMakeDirectoryInformation.cmake<br />
| | | |-- progress.marks<br />
| | | `-- simple_test.dir<br />
| | | |-- C.includecache<br />
| | | |-- DependInfo.cmake<br />
| | | |-- build.make<br />
| | | |-- cmake_clean.cmake<br />
| | | |-- depend.internal<br />
| | | |-- depend.make<br />
| | | |-- flags.make<br />
| | | |-- link.txt<br />
| | | |-- progress.make<br />
| | | `-- simple_test.c.o<br />
| | |-- Makefile<br />
| | |-- cmake_install.cmake<br />
| | `-- simple_test<br />
| `-- slaveinfo<br />
| |-- CMakeFiles<br />
| | |-- CMakeDirectoryInformation.cmake<br />
| | |-- progress.marks<br />
| | `-- slaveinfo.dir<br />
| | |-- C.includecache<br />
| | |-- DependInfo.cmake<br />
| | |-- build.make<br />
| | |-- cmake_clean.cmake<br />
| | |-- depend.internal<br />
| | |-- depend.make<br />
| | |-- flags.make<br />
| | |-- link.txt<br />
| | |-- progress.make<br />
| | `-- slaveinfo.c.o<br />
| |-- Makefile<br />
| |-- cmake_install.cmake<br />
| `-- slaveinfo<br />
`-- simple_ng<br />
|-- CMakeFiles<br />
| |-- CMakeDirectoryInformation.cmake<br />
| |-- progress.marks<br />
| `-- simple_ng.dir<br />
| |-- C.includecache<br />
| |-- DependInfo.cmake<br />
| |-- build.make<br />
| |-- cmake_clean.cmake<br />
| |-- depend.internal<br />
| |-- depend.make<br />
| |-- flags.make<br />
| |-- link.txt<br />
| |-- progress.make<br />
| `-- simple_ng.c.o<br />
|-- Makefile<br />
|-- cmake_install.cmake<br />
`-- simple_ng</p>
<p>29 directories, 100 files<br />
lhj@lhj:~/SOEM/build_pc$</p>
</div>
<p> </p>
<h1 ><b>开发板端</b></h1>
<h2 ><b>编译</b></h2>
<p >cd SOEM/</p>
<p >export CC=aarch64-linux-gnu-gcc</p>
<p >mkdir build</p>
<p > </p>
<p >cd build/</p>
<p > </p>
<p >cmake ..</p>
<div class="parsedown-markdown">
<p>lhj@lhj:~/SOEM/build$ cmake ..</p>
<p >-- The C compiler identification is GNU 9.4.0</p>
<p >-- Check for working C compiler: /usr/bin/aarch64-linux-gnu-gcc</p>
<p >-- Check for working C compiler: /usr/bin/aarch64-linux-gnu-gcc -- works</p>
<p >-- Detecting C compiler ABI info</p>
<p >-- Detecting C compiler ABI info - done</p>
<p >-- Detecting C compile features</p>
<p >-- Detecting C compile features - done</p>
<p >-- OS is linux</p>
<p >-- LIB_DIR: lib</p>
<p >-- Configuring done</p>
<p >-- Generating done</p>
<p >-- Build files have been written to: /home/lhj/SOEM/build</p>
<p >lhj@lhj:~/SOEM/build$</p>
</div>
<p > </p>
<p > </p>
<p >make</p>
<div class="parsedown-markdown">
<p>lhj@lhj:~/SOEM/build$ make</p>
<p >Scanning dependencies of target soem</p>
<p >[ 4%] Building C object CMakeFiles/soem.dir/soem/ethercatbase.c.o</p>
<p >[ 9%] Building C object CMakeFiles/soem.dir/soem/ethercatcoe.c.o</p>
<p >[ 14%] Building C object CMakeFiles/soem.dir/soem/ethercatconfig.c.o</p>
<p >[ 19%] Building C object CMakeFiles/soem.dir/soem/ethercatdc.c.o</p>
<p >[ 23%] Building C object CMakeFiles/soem.dir/soem/ethercateoe.c.o</p>
<p >[ 28%] Building C object CMakeFiles/soem.dir/soem/ethercatfoe.c.o</p>
<p >[ 33%] Building C object CMakeFiles/soem.dir/soem/ethercatmain.c.o</p>
<p >[ 38%] Building C object CMakeFiles/soem.dir/soem/ethercatprint.c.o</p>
<p >[ 42%] Building C object CMakeFiles/soem.dir/soem/ethercatsoe.c.o</p>
<p >[ 47%] Building C object CMakeFiles/soem.dir/osal/linux/osal.c.o</p>
<p >[ 52%] Building C object CMakeFiles/soem.dir/oshw/linux/nicdrv.c.o</p>
<p >[ 57%] Building C object CMakeFiles/soem.dir/oshw/linux/oshw.c.o</p>
<p >[ 61%] Linking C static library libsoem.a</p>
<p >[ 61%] Built target soem</p>
<p >Scanning dependencies of target simple_ng</p>
<p >[ 66%] Building C object test/simple_ng/CMakeFiles/simple_ng.dir/simple_ng.c.o</p>
<p >[ 71%] Linking C executable simple_ng</p>
<p >[ 71%] Built target simple_ng</p>
<p >Scanning dependencies of target slaveinfo</p>
<p >[ 76%] Building C object test/linux/slaveinfo/CMakeFiles/slaveinfo.dir/slaveinfo.c.o</p>
<p >[ 80%] Linking C executable slaveinfo</p>
<p >[ 80%] Built target slaveinfo</p>
<p >Scanning dependencies of target eepromtool</p>
<p >[ 85%] Building C object test/linux/eepromtool/CMakeFiles/eepromtool.dir/eepromtool.c.o</p>
<p >[ 90%] Linking C executable eepromtool</p>
<p >[ 90%] Built target eepromtool</p>
<p >Scanning dependencies of target simple_test</p>
<p >[ 95%] Building C object test/linux/simple_test/CMakeFiles/simple_test.dir/simple_test.c.o</p>
<p > Linking C executable simple_test</p>
<p > Built target simple_test</p>
<p >lhj@lhj:~/SOEM/build$</p>
</div>
<p > </p>
<h2 ><b>部署</b></h2>
<p >cp libsoem.a /mnt/d</p>
<p >cp test/linux/simple_test/simple_test /mnt/d</p>
<p >cp test/linux/slaveinfo/slaveinfo /mnt/d</p>
<p >将上述文件rz导入开发板</p>
<p >chmod +x simple_test slaveinfo</p>
<h2 ><b>运行</b></h2>
<div class="parsedown-markdown">
<p>root@myir-yg2lx:~# ./slaveinfo eth0</p>
<p >SOEM (Simple Open EtherCAT Master)</p>
<p >Slaveinfo</p>
<p >Starting slaveinfo</p>
<p >ec_init on eth0 succeeded.</p>
<p >No slaves found!</p>
<p >End slaveinfo, close socket</p>
<p >End program</p>
</div>
<p > </p>
<div class="parsedown-markdown">
<p>root@myir-yg2lx:~# ./simple_test eth0</p>
<p >SOEM (Simple Open EtherCAT Master)</p>
<p >Simple test</p>
<p >Starting simple test</p>
<p >ec_init on eth0 succeeded.</p>
<p >No slaves found!</p>
<p >End simple test, close socket</p>
<p >End program</p>
<p >root@myir-yg2lx:~#</p>
</div>
<p > </p>
<h1 ><b>总结</b></h1>
<p >本开发板接口资源丰富,性能强,特别适合工控领域的应用,比如作为EtherCAT主站。由于没有从站,所以暂时未能演示和从站通讯的功能。</p>
<p > </p>
</div><script> var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
(function($){
var postHeight = getTextHeight(400);
$(".showpostmsg").html($(".showpostmsg").html());
$(".showpostmsg").after(loginstr);
$(".showpostmsg").css({height:postHeight,overflow:"hidden"});
})(jQuery);
} </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script>
页:
[1]