【米尔MYD-YG2LX开发板】在工控领域的应用-modbus开发环境搭建
<div class='showpostmsg'><h1><b>前言</b></h1><p >本文介绍基于【米尔MYD-YG2LX开发板】在工控领域的应用</p>
<p >,modbus开发环境搭建。开发环境基于WSL2.</p>
<p > </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 > </p>
<h1 ><b>PC端</b></h1>
<h2 ><b>编译</b></h2>
<p >sudo su 切换到root用户</p>
<p >cd libmodbus/</p>
<p > </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, 'build-aux'.</p>
<p >libtoolize: linking file 'build-aux/ltmain.sh'</p>
<p >libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.</p>
<p >libtoolize: linking file 'm4/libtool.m4'</p>
<p >libtoolize: linking file 'm4/ltoptions.m4'</p>
<p >libtoolize: linking file 'm4/ltsugar.m4'</p>
<p >libtoolize: linking file 'm4/ltversion.m4'</p>
<p >libtoolize: linking file 'm4/lt~obsolete.m4'</p>
<p >configure.ac:33: installing 'build-aux/compile'</p>
<p >configure.ac:56: installing 'build-aux/config.guess'</p>
<p >configure.ac:56: installing 'build-aux/config.sub'</p>
<p >configure.ac:32: installing 'build-aux/install-sh'</p>
<p >configure.ac:32: installing 'build-aux/missing'</p>
<p >src/Makefile.am: installing 'build-aux/depcomp'</p>
<p >parallel-tests: installing 'build-aux/test-driver'</p>
<p > </p>
<p >------------------------------------------------------</p>
<p >Initialized build system. You can now run ./configure</p>
<p >------------------------------------------------------</p>
<p > </p>
<p >lhj@lhj:~/libmodbus$</p>
<p > </p>
<p >./configure && make install</p>
</div>
<p > </p>
<p >tests目录下是测试Demo</p>
<div class="parsedown-markdown">
<p>root@lhj:/home/lhj/libmodbus# ls tests/</p>
<p >LICENSE bandwidth-client.o random-test-client unit-test-client unit-test.h.in</p>
<p >Makefile bandwidth-server-many-up random-test-client.c unit-test-client.c unit-tests.sh</p>
<p >Makefile.am bandwidth-server-many-up.c random-test-client.o unit-test-client.o version</p>
<p >Makefile.in bandwidth-server-many-up.o random-test-server unit-test-server version.c</p>
<p >README.md bandwidth-server-one random-test-server.c unit-test-server.c version.o</p>
<p >bandwidth-client bandwidth-server-one.c random-test-server.o unit-test-server.o</p>
<p >bandwidth-client.c bandwidth-server-one.o stamp-h2 unit-test.h</p>
<p >root@lhj:/home/lhj/libmodbus#</p>
</div>
<p > </p>
<p > </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 'chexk'. Stop.</p>
<p >root@lhj:/home/lhj/libmodbus# make check</p>
<p >Making check in src</p>
<p >make: Nothing to be done for 'check'.</p>
<p >Making check in tests</p>
<p >make 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: 1</p>
<p ># SKIP: 0</p>
<p ># XFAIL: 0</p>
<p ># FAIL: 0</p>
<p ># XPASS: 0</p>
<p ># ERROR: 0</p>
<p >============================================================================</p>
<p >root@lhj:/home/lhj/libmodbus#</p>
</div>
<p > </p>
<p > </p>
<h1 ><b>开发板板端</b></h1>
<h2 ><b>编译</b></h2>
<p >mkdir output</p>
<p > </p>
<p >./configure --host=arm-linux-gnueabihf --prefix=/home/lhj/libmodbus/output --enable-shared --enable-static</p>
<p > </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 > CC modbus.lo</p>
<p > CC modbus-data.lo</p>
<p > CC modbus-rtu.lo</p>
<p > CC modbus-tcp.lo</p>
<p > CCLD libmodbus.la</p>
<p >Making all in tests</p>
<p >make all-am</p>
<p > CC bandwidth-server-one.o</p>
<p > CCLD bandwidth-server-one</p>
<p > CC bandwidth-server-many-up.o</p>
<p > CCLD bandwidth-server-many-up</p>
<p > CC bandwidth-client.o</p>
<p > CCLD bandwidth-client</p>
<p > CC random-test-server.o</p>
<p > CCLD random-test-server</p>
<p > CC random-test-client.o</p>
<p > CCLD random-test-client</p>
<p > CC unit-test-server.o</p>
<p > CCLD unit-test-server</p>
<p > CC unit-test-client.o</p>
<p > CCLD unit-test-client</p>
<p > CC version.o</p>
<p > CCLD version</p>
<p >make: Nothing to be done for 'all-am'.</p>
</div>
<p > </p>
<p > </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 > /usr/bin/mkdir -p '/home/lhj/libmodbus/output/lib'</p>
<p > /bin/sh ../libtool --mode=install /usr/bin/install -c libmodbus.la '/home/lhj/libmodbus/output/lib'</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 && { ln -s -f libmodbus.so.5.1.0 libmodbus.so.5 || { rm -f libmodbus.so.5 && ln -s libmodbus.so.5.1.0 libmodbus.so.5; }; })</p>
<p >libtool: install: (cd /home/lhj/libmodbus/output/lib && { ln -s -f libmodbus.so.5.1.0 libmodbus.so || { rm -f libmodbus.so && 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="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/sbin" ldconfig -n /home/lhj/libmodbus/output/lib</p>
<p >----------------------------------------------------------------------</p>
<p >Libraries have been installed in:</p>
<p > /home/lhj/libmodbus/output/lib</p>
<p > </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 '-LLIBDIR'</p>
<p >flag during linking and do at least one of the following:</p>
<p > - add LIBDIR to the 'LD_LIBRARY_PATH' environment variable</p>
<p > during execution</p>
<p > - add LIBDIR to the 'LD_RUN_PATH' environment variable</p>
<p > during linking</p>
<p > - use the '-Wl,-rpath -Wl,LIBDIR' linker flag</p>
<p > - have your system administrator add LIBDIR to '/etc/ld.so.conf'</p>
<p > </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 > /usr/bin/mkdir -p '/home/lhj/libmodbus/output/include/modbus'</p>
<p > /usr/bin/install -c -m 644 modbus.h modbus-version.h modbus-rtu.h modbus-tcp.h '/home/lhj/libmodbus/output/include/modbus'</p>
<p >Making install in tests</p>
<p >make: Nothing to be done for 'install-exec-am'.</p>
<p >make: Nothing to be done for 'install-data-am'.</p>
<p >make: Nothing to be done for 'install-exec-am'.</p>
<p > /usr/bin/mkdir -p '/home/lhj/libmodbus/output/share/doc/libmodbus'</p>
<p > /usr/bin/install -c -m 644 AUTHORS NEWS README.md '/home/lhj/libmodbus/output/share/doc/libmodbus'</p>
<p > /usr/bin/mkdir -p '/home/lhj/libmodbus/output/lib/pkgconfig'</p>
<p > /usr/bin/install -c -m 644 libmodbus.pc '/home/lhj/libmodbus/output/lib/pkgconfig'</p>
<p >root@lhj:/home/lhj/libmodbus#</p>
</div>
<p > </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 >| `-- modbus</p>
<p >| |-- modbus-rtu.h</p>
<p >| |-- modbus-tcp.h</p>
<p >| |-- modbus-version.h</p>
<p >| `-- modbus.h</p>
<p >|-- lib</p>
<p >| |-- libmodbus.a</p>
<p >| |-- libmodbus.la</p>
<p >| |-- libmodbus.so -> libmodbus.so.5.1.0</p>
<p >| |-- libmodbus.so.5 -> libmodbus.so.5.1.0</p>
<p >| |-- libmodbus.so.5.1.0</p>
<p >| `-- pkgconfig</p>
<p >| `-- libmodbus.pc</p>
<p >`-- share</p>
<p > `-- doc</p>
<p > `-- libmodbus</p>
<p > |-- AUTHORS</p>
<p > |-- NEWS</p>
<p > `-- README.md</p>
<p > </p>
<p >7 directories, 13 files</p>
<p >root@lhj:/home/lhj/libmodbus#</p>
</div>
<p > </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 > </p>
<p >./unit-test-client</p>
<p >./unit-test-server</p>
<h1 ><b>总结</b></h1>
<p >本开发板接口资源丰富,性能强,特别适合工控领域的应用,比如实现modbus通讯。</p>
<p > </p>
<p > </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> <p>modbus开发环境搭建感觉不是很简单,这么多代码要整吗</p>
<p>楼主只是安装了libmodbus库,并运行了其自带的自检程序。</p>
<p>楼主还没有编写自己的驱动代码呢!</p>
<p>文中只是几条命令的操作而已,没有代码的。</p>
<p>这个LINUX怎么这么麻烦,是不是一辈子也开发不出来什么东东</p>
页:
[1]