2248|3

501

帖子

4

TA的资源

纯净的硅(高级)

楼主
 

【米尔MYD-YG2LX开发板】在工控领域的应用-modbus开发环境搭建 [复制链接]

前言

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

,modbus开发环境搭建。开发环境基于WSL2.

 

下载代码

git clone https://github.com/stephane/libmodbus.git

 

PC端

编译

sudo su 切换到root用户

cd libmodbus/

 

./autogen.sh

lhj@lhj:~/libmodbus$ ./autogen.sh

libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, 'build-aux'.

libtoolize: linking file 'build-aux/ltmain.sh'

libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.

libtoolize: linking file 'm4/libtool.m4'

libtoolize: linking file 'm4/ltoptions.m4'

libtoolize: linking file 'm4/ltsugar.m4'

libtoolize: linking file 'm4/ltversion.m4'

libtoolize: linking file 'm4/lt~obsolete.m4'

configure.ac:33: installing 'build-aux/compile'

configure.ac:56: installing 'build-aux/config.guess'

configure.ac:56: installing 'build-aux/config.sub'

configure.ac:32: installing 'build-aux/install-sh'

configure.ac:32: installing 'build-aux/missing'

src/Makefile.am: installing 'build-aux/depcomp'

parallel-tests: installing 'build-aux/test-driver'

 

------------------------------------------------------

Initialized build system. You can now run ./configure

------------------------------------------------------

 

lhj@lhj:~/libmodbus$

 

./configure && make install

 

tests目录下是测试Demo

root@lhj:/home/lhj/libmodbus# ls tests/

LICENSE             bandwidth-client.o          random-test-client    unit-test-client    unit-test.h.in

Makefile            bandwidth-server-many-up    random-test-client.c  unit-test-client.c  unit-tests.sh

Makefile.am         bandwidth-server-many-up.c  random-test-client.o  unit-test-client.o  version

Makefile.in         bandwidth-server-many-up.o  random-test-server    unit-test-server    version.c

README.md           bandwidth-server-one        random-test-server.c  unit-test-server.c  version.o

bandwidth-client    bandwidth-server-one.c      random-test-server.o  unit-test-server.o

bandwidth-client.c  bandwidth-server-one.o      stamp-h2              unit-test.h

root@lhj:/home/lhj/libmodbus#

 

 

测试

make chexk

root@lhj:/home/lhj/libmodbus# make chexk

make: *** No rule to make target 'chexk'.  Stop.

root@lhj:/home/lhj/libmodbus# make check

Making check in src

make[1]: Nothing to be done for 'check'.

Making check in tests

make  check-TESTS

PASS: unit-tests.sh

============================================================================

Testsuite summary for libmodbus 3.1.10

============================================================================

# TOTAL: 1

# PASS:  1

# SKIP:  0

# XFAIL: 0

# FAIL:  0

# XPASS: 0

# ERROR: 0

============================================================================

root@lhj:/home/lhj/libmodbus#

 

 

开发板板端

编译

mkdir output

 

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

 

make

root@lhj:/home/lhj/libmodbus# make

make --no-print-directory all-recursive

Making all in src

  CC       modbus.lo

  CC       modbus-data.lo

  CC       modbus-rtu.lo

  CC       modbus-tcp.lo

  CCLD     libmodbus.la

Making all in tests

make  all-am

  CC       bandwidth-server-one.o

  CCLD     bandwidth-server-one

  CC       bandwidth-server-many-up.o

  CCLD     bandwidth-server-many-up

  CC       bandwidth-client.o

  CCLD     bandwidth-client

  CC       random-test-server.o

  CCLD     random-test-server

  CC       random-test-client.o

  CCLD     random-test-client

  CC       unit-test-server.o

  CCLD     unit-test-server

  CC       unit-test-client.o

  CCLD     unit-test-client

  CC       version.o

  CCLD     version

make[2]: Nothing to be done for 'all-am'.

 

 

make install

root@lhj:/home/lhj/libmodbus# make install

Making install in src

 /usr/bin/mkdir -p '/home/lhj/libmodbus/output/lib'

 /bin/sh ../libtool   --mode=install /usr/bin/install -c   libmodbus.la '/home/lhj/libmodbus/output/lib'

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

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; }; })

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; }; })

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

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

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

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

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

----------------------------------------------------------------------

Libraries have been installed in:

   /home/lhj/libmodbus/output/lib

 

If you ever happen to want to link against installed libraries

in a given directory, LIBDIR, you must either use libtool, and

specify the full pathname of the library, or use the '-LLIBDIR'

flag during linking and do at least one of the following:

   - add LIBDIR to the 'LD_LIBRARY_PATH' environment variable

     during execution

   - add LIBDIR to the 'LD_RUN_PATH' environment variable

     during linking

   - use the '-Wl,-rpath -Wl,LIBDIR' linker flag

   - have your system administrator add LIBDIR to '/etc/ld.so.conf'

 

See any operating system documentation about shared libraries for

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

----------------------------------------------------------------------

 /usr/bin/mkdir -p '/home/lhj/libmodbus/output/include/modbus'

 /usr/bin/install -c -m 644 modbus.h modbus-version.h modbus-rtu.h modbus-tcp.h '/home/lhj/libmodbus/output/include/modbus'

Making install in tests

make[2]: Nothing to be done for 'install-exec-am'.

make[2]: Nothing to be done for 'install-data-am'.

make[2]: Nothing to be done for 'install-exec-am'.

 /usr/bin/mkdir -p '/home/lhj/libmodbus/output/share/doc/libmodbus'

 /usr/bin/install -c -m 644 AUTHORS NEWS README.md '/home/lhj/libmodbus/output/share/doc/libmodbus'

 /usr/bin/mkdir -p '/home/lhj/libmodbus/output/lib/pkgconfig'

 /usr/bin/install -c -m 644 libmodbus.pc '/home/lhj/libmodbus/output/lib/pkgconfig'

root@lhj:/home/lhj/libmodbus#

 

部署

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

root@lhj:/home/lhj/libmodbus# tree output/

output/

|-- include

|   `-- modbus

|       |-- modbus-rtu.h

|       |-- modbus-tcp.h

|       |-- modbus-version.h

|       `-- modbus.h

|-- lib

|   |-- libmodbus.a

|   |-- libmodbus.la

|   |-- libmodbus.so -> libmodbus.so.5.1.0

|   |-- libmodbus.so.5 -> libmodbus.so.5.1.0

|   |-- libmodbus.so.5.1.0

|   `-- pkgconfig

|       `-- libmodbus.pc

`-- share

    `-- doc

        `-- libmodbus

            |-- AUTHORS

            |-- NEWS

            `-- README.md

 

7 directories, 13 files

root@lhj:/home/lhj/libmodbus#

 

测试

cp tests/unit-test-server /mnt/d

cp tests/unit-test-client /mnt/d

然后导入到开发板

chmod +x unit-test-server unit-test-client

 

./unit-test-client

./unit-test-server

总结

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

 

 

 

此帖出自工控电子论坛

最新回复

这个LINUX怎么这么麻烦,是不是一辈子也开发不出来什么东东   详情 回复 发表于 2023-7-17 08:28
点赞 关注
 

回复
举报

6614

帖子

0

TA的资源

五彩晶圆(高级)

沙发
 

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

此帖出自工控电子论坛
 
 

回复

625

帖子

0

TA的资源

纯净的硅(高级)

板凳
 

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

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

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

此帖出自工控电子论坛
 
 

回复

1万

帖子

16

TA的资源

版主

4
 

这个LINUX怎么这么麻烦,是不是一辈子也开发不出来什么东东

此帖出自工控电子论坛
个人签名http://shop34182318.taobao.com/
https://shop436095304.taobao.com/?spm=a230r.7195193.1997079397.37.69fe60dfT705yr
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/10 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表