qinyunti 发表于 2023-6-11 00:07

【米尔MYD-YG2LX开发板】在工控领域的应用-modbus开发环境搭建

<div class='showpostmsg'><h1><b>前言</b></h1>

<p >本文介绍基于【米尔MYD-YG2LX开发板】在工控领域的应用</p>

<p >,modbus开发环境搭建。开发环境基于WSL2.</p>

<p >&nbsp;</p>

<h1 ><b>下载代码</b></h1>

<p >git clone <a href="https://github.com/stephane/libmodbus.git"><u>https://github.com/stephane/libmodbus.git</u></a></p>

<p >&nbsp;</p>

<h1 ><b>PC端</b></h1>

<h2 ><b>编译</b></h2>

<p >sudo su 切换到root用户</p>

<p >cd libmodbus/</p>

<p >&nbsp;</p>

<p >./autogen.sh</p>

<div class="parsedown-markdown">
<p>lhj@lhj:~/libmodbus$ ./autogen.sh</p>

<p >libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, &#39;build-aux&#39;.</p>

<p >libtoolize: linking file &#39;build-aux/ltmain.sh&#39;</p>

<p >libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, &#39;m4&#39;.</p>

<p >libtoolize: linking file &#39;m4/libtool.m4&#39;</p>

<p >libtoolize: linking file &#39;m4/ltoptions.m4&#39;</p>

<p >libtoolize: linking file &#39;m4/ltsugar.m4&#39;</p>

<p >libtoolize: linking file &#39;m4/ltversion.m4&#39;</p>

<p >libtoolize: linking file &#39;m4/lt~obsolete.m4&#39;</p>

<p >configure.ac:33: installing &#39;build-aux/compile&#39;</p>

<p >configure.ac:56: installing &#39;build-aux/config.guess&#39;</p>

<p >configure.ac:56: installing &#39;build-aux/config.sub&#39;</p>

<p >configure.ac:32: installing &#39;build-aux/install-sh&#39;</p>

<p >configure.ac:32: installing &#39;build-aux/missing&#39;</p>

<p >src/Makefile.am: installing &#39;build-aux/depcomp&#39;</p>

<p >parallel-tests: installing &#39;build-aux/test-driver&#39;</p>

<p >&nbsp;</p>

<p >------------------------------------------------------</p>

<p >Initialized build system. You can now run ./configure</p>

<p >------------------------------------------------------</p>

<p >&nbsp;</p>

<p >lhj@lhj:~/libmodbus$</p>

<p >&nbsp;</p>

<p >./configure &amp;&amp; make install</p>
</div>

<p >&nbsp;</p>

<p >tests目录下是测试Demo</p>

<div class="parsedown-markdown">
<p>root@lhj:/home/lhj/libmodbus# ls tests/</p>

<p >LICENSE &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bandwidth-client.o &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;random-test-client &nbsp;&nbsp;&nbsp;unit-test-client &nbsp;&nbsp;&nbsp;unit-test.h.in</p>

<p >Makefile &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bandwidth-server-many-up &nbsp;&nbsp;&nbsp;random-test-client.c &nbsp;unit-test-client.c &nbsp;unit-tests.sh</p>

<p >Makefile.am &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bandwidth-server-many-up.c &nbsp;random-test-client.o &nbsp;unit-test-client.o &nbsp;version</p>

<p >Makefile.in &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bandwidth-server-many-up.o &nbsp;random-test-server &nbsp;&nbsp;&nbsp;unit-test-server &nbsp;&nbsp;&nbsp;version.c</p>

<p >README.md &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bandwidth-server-one &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;random-test-server.c &nbsp;unit-test-server.c &nbsp;version.o</p>

<p >bandwidth-client &nbsp;&nbsp;&nbsp;bandwidth-server-one.c &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;random-test-server.o &nbsp;unit-test-server.o</p>

<p >bandwidth-client.c &nbsp;bandwidth-server-one.o &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stamp-h2 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;unit-test.h</p>

<p >root@lhj:/home/lhj/libmodbus#</p>
</div>

<p >&nbsp;</p>

<p >&nbsp;</p>

<h2 ><b>测试</b></h2>

<p >make chexk</p>

<div class="parsedown-markdown">
<p>root@lhj:/home/lhj/libmodbus# make chexk</p>

<p >make: *** No rule to make target &#39;chexk&#39;. &nbsp;Stop.</p>

<p >root@lhj:/home/lhj/libmodbus# make check</p>

<p >Making check in src</p>

<p >make: Nothing to be done for &#39;check&#39;.</p>

<p >Making check in tests</p>

<p >make &nbsp;check-TESTS</p>

<p >PASS: unit-tests.sh</p>

<p >============================================================================</p>

<p >Testsuite summary for libmodbus 3.1.10</p>

<p >============================================================================</p>

<p ># TOTAL: 1</p>

<p ># PASS: &nbsp;1</p>

<p ># SKIP: &nbsp;0</p>

<p ># XFAIL: 0</p>

<p ># FAIL: &nbsp;0</p>

<p ># XPASS: 0</p>

<p ># ERROR: 0</p>

<p >============================================================================</p>

<p >root@lhj:/home/lhj/libmodbus#</p>
</div>

<p >&nbsp;</p>

<p >&nbsp;</p>

<h1 ><b>开发板板端</b></h1>

<h2 ><b>编译</b></h2>

<p >mkdir output</p>

<p >&nbsp;</p>

<p >./configure --host=arm-linux-gnueabihf --prefix=/home/lhj/libmodbus/output --enable-shared --enable-static</p>

<p >&nbsp;</p>

<p >make</p>

<div class="parsedown-markdown">
<p>root@lhj:/home/lhj/libmodbus# make</p>

<p >make --no-print-directory all-recursive</p>

<p >Making all in src</p>

<p >&nbsp;&nbsp;CC &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;modbus.lo</p>

<p >&nbsp;&nbsp;CC &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;modbus-data.lo</p>

<p >&nbsp;&nbsp;CC &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;modbus-rtu.lo</p>

<p >&nbsp;&nbsp;CC &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;modbus-tcp.lo</p>

<p >&nbsp;&nbsp;CCLD &nbsp;&nbsp;&nbsp;&nbsp;libmodbus.la</p>

<p >Making all in tests</p>

<p >make &nbsp;all-am</p>

<p >&nbsp;&nbsp;CC &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bandwidth-server-one.o</p>

<p >&nbsp;&nbsp;CCLD &nbsp;&nbsp;&nbsp;&nbsp;bandwidth-server-one</p>

<p >&nbsp;&nbsp;CC &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bandwidth-server-many-up.o</p>

<p >&nbsp;&nbsp;CCLD &nbsp;&nbsp;&nbsp;&nbsp;bandwidth-server-many-up</p>

<p >&nbsp;&nbsp;CC &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bandwidth-client.o</p>

<p >&nbsp;&nbsp;CCLD &nbsp;&nbsp;&nbsp;&nbsp;bandwidth-client</p>

<p >&nbsp;&nbsp;CC &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;random-test-server.o</p>

<p >&nbsp;&nbsp;CCLD &nbsp;&nbsp;&nbsp;&nbsp;random-test-server</p>

<p >&nbsp;&nbsp;CC &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;random-test-client.o</p>

<p >&nbsp;&nbsp;CCLD &nbsp;&nbsp;&nbsp;&nbsp;random-test-client</p>

<p >&nbsp;&nbsp;CC &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;unit-test-server.o</p>

<p >&nbsp;&nbsp;CCLD &nbsp;&nbsp;&nbsp;&nbsp;unit-test-server</p>

<p >&nbsp;&nbsp;CC &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;unit-test-client.o</p>

<p >&nbsp;&nbsp;CCLD &nbsp;&nbsp;&nbsp;&nbsp;unit-test-client</p>

<p >&nbsp;&nbsp;CC &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;version.o</p>

<p >&nbsp;&nbsp;CCLD &nbsp;&nbsp;&nbsp;&nbsp;version</p>

<p >make: Nothing to be done for &#39;all-am&#39;.</p>
</div>

<p >&nbsp;</p>

<p >&nbsp;</p>

<p >make install</p>

<div class="parsedown-markdown">
<p>root@lhj:/home/lhj/libmodbus# make install</p>

<p >Making install in src</p>

<p >&nbsp;/usr/bin/mkdir -p &#39;/home/lhj/libmodbus/output/lib&#39;</p>

<p >&nbsp;/bin/sh ../libtool &nbsp;&nbsp;--mode=install /usr/bin/install -c &nbsp;&nbsp;libmodbus.la &#39;/home/lhj/libmodbus/output/lib&#39;</p>

<p >libtool: install: /usr/bin/install -c .libs/libmodbus.so.5.1.0 /home/lhj/libmodbus/output/lib/libmodbus.so.5.1.0</p>

<p >libtool: install: (cd /home/lhj/libmodbus/output/lib &amp;&amp; { ln -s -f libmodbus.so.5.1.0 libmodbus.so.5 || { rm -f libmodbus.so.5 &amp;&amp; ln -s libmodbus.so.5.1.0 libmodbus.so.5; }; })</p>

<p >libtool: install: (cd /home/lhj/libmodbus/output/lib &amp;&amp; { ln -s -f libmodbus.so.5.1.0 libmodbus.so || { rm -f libmodbus.so &amp;&amp; ln -s libmodbus.so.5.1.0 libmodbus.so; }; })</p>

<p >libtool: install: /usr/bin/install -c .libs/libmodbus.lai /home/lhj/libmodbus/output/lib/libmodbus.la</p>

<p >libtool: install: /usr/bin/install -c .libs/libmodbus.a /home/lhj/libmodbus/output/lib/libmodbus.a</p>

<p >libtool: install: chmod 644 /home/lhj/libmodbus/output/lib/libmodbus.a</p>

<p >libtool: install: arm-linux-gnueabihf-ranlib /home/lhj/libmodbus/output/lib/libmodbus.a</p>

<p >libtool: finish: PATH=&quot;/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/sbin&quot; ldconfig -n /home/lhj/libmodbus/output/lib</p>

<p >----------------------------------------------------------------------</p>

<p >Libraries have been installed in:</p>

<p >&nbsp;&nbsp;&nbsp;/home/lhj/libmodbus/output/lib</p>

<p >&nbsp;</p>

<p >If you ever happen to want to link against installed libraries</p>

<p >in a given directory, LIBDIR, you must either use libtool, and</p>

<p >specify the full pathname of the library, or use the &#39;-LLIBDIR&#39;</p>

<p >flag during linking and do at least one of the following:</p>

<p >&nbsp;&nbsp;&nbsp;- add LIBDIR to the &#39;LD_LIBRARY_PATH&#39; environment variable</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;during execution</p>

<p >&nbsp;&nbsp;&nbsp;- add LIBDIR to the &#39;LD_RUN_PATH&#39; environment variable</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;during linking</p>

<p >&nbsp;&nbsp;&nbsp;- use the &#39;-Wl,-rpath -Wl,LIBDIR&#39; linker flag</p>

<p >&nbsp;&nbsp;&nbsp;- have your system administrator add LIBDIR to &#39;/etc/ld.so.conf&#39;</p>

<p >&nbsp;</p>

<p >See any operating system documentation about shared libraries for</p>

<p >more information, such as the ld(1) and ld.so(8) manual pages.</p>

<p >----------------------------------------------------------------------</p>

<p >&nbsp;/usr/bin/mkdir -p &#39;/home/lhj/libmodbus/output/include/modbus&#39;</p>

<p >&nbsp;/usr/bin/install -c -m 644 modbus.h modbus-version.h modbus-rtu.h modbus-tcp.h &#39;/home/lhj/libmodbus/output/include/modbus&#39;</p>

<p >Making install in tests</p>

<p >make: Nothing to be done for &#39;install-exec-am&#39;.</p>

<p >make: Nothing to be done for &#39;install-data-am&#39;.</p>

<p >make: Nothing to be done for &#39;install-exec-am&#39;.</p>

<p >&nbsp;/usr/bin/mkdir -p &#39;/home/lhj/libmodbus/output/share/doc/libmodbus&#39;</p>

<p >&nbsp;/usr/bin/install -c -m 644 AUTHORS NEWS README.md &#39;/home/lhj/libmodbus/output/share/doc/libmodbus&#39;</p>

<p >&nbsp;/usr/bin/mkdir -p &#39;/home/lhj/libmodbus/output/lib/pkgconfig&#39;</p>

<p >&nbsp;/usr/bin/install -c -m 644 libmodbus.pc &#39;/home/lhj/libmodbus/output/lib/pkgconfig&#39;</p>

<p >root@lhj:/home/lhj/libmodbus#</p>
</div>

<p >&nbsp;</p>

<h2 ><b>部署</b></h2>

<p >查看生成文件如下,将头文件和库文件导入到开发板即可</p>

<div class="parsedown-markdown">
<p>root@lhj:/home/lhj/libmodbus# tree output/</p>

<p >output/</p>

<p >|-- include</p>

<p >| &nbsp;&nbsp;`-- modbus</p>

<p >| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|-- modbus-rtu.h</p>

<p >| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|-- modbus-tcp.h</p>

<p >| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|-- modbus-version.h</p>

<p >| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`-- modbus.h</p>

<p >|-- lib</p>

<p >| &nbsp;&nbsp;|-- libmodbus.a</p>

<p >| &nbsp;&nbsp;|-- libmodbus.la</p>

<p >| &nbsp;&nbsp;|-- libmodbus.so -&gt; libmodbus.so.5.1.0</p>

<p >| &nbsp;&nbsp;|-- libmodbus.so.5 -&gt; libmodbus.so.5.1.0</p>

<p >| &nbsp;&nbsp;|-- libmodbus.so.5.1.0</p>

<p >| &nbsp;&nbsp;`-- pkgconfig</p>

<p >| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`-- libmodbus.pc</p>

<p >`-- share</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;`-- doc</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`-- libmodbus</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|-- AUTHORS</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|-- NEWS</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`-- README.md</p>

<p >&nbsp;</p>

<p >7 directories, 13 files</p>

<p >root@lhj:/home/lhj/libmodbus#</p>
</div>

<p >&nbsp;</p>

<h2 ><b>测试</b></h2>

<p >cp tests/unit-test-server /mnt/d</p>

<p >cp tests/unit-test-client /mnt/d</p>

<p >然后导入到开发板</p>

<p >chmod +x unit-test-server unit-test-client</p>

<p >&nbsp;</p>

<p >./unit-test-client</p>

<p >./unit-test-server</p>

<h1 ><b>总结</b></h1>

<p >本开发板接口资源丰富,性能强,特别适合工控领域的应用,比如实现modbus通讯。</p>

<p >&nbsp;</p>

<p >&nbsp;</p>

<p >&nbsp;</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>

Jacktang 发表于 2023-6-12 07:33

<p>modbus开发环境搭建感觉不是很简单,这么多代码要整吗</p>

jobszheng5 发表于 2023-6-13 10:18

<p>楼主只是安装了libmodbus库,并运行了其自带的自检程序。</p>

<p>楼主还没有编写自己的驱动代码呢!</p>

<p>文中只是几条命令的操作而已,没有代码的。</p>

ddllxxrr 发表于 2023-7-17 08:28

<p>这个LINUX怎么这么麻烦,是不是一辈子也开发不出来什么东东</p>
页: [1]
查看完整版本: 【米尔MYD-YG2LX开发板】在工控领域的应用-modbus开发环境搭建