导航

    全志在线开发者论坛

    • 注册
    • 登录
    • 搜索
    • 版块
    • 话题
    • 在线文档
    • 社区主页

    飞凌OK-T527开发板试用3-modbus使用

    飞凌嵌入式专区
    1
    1
    878
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • Z
      zxfeng LV 3 最后由 编辑

      源码下载

      文档:https://libmodbus.org/getting_started/
      源码:https://github.com/stephane/libmodbus/releases
      目前最新的为3.1.10

      交叉编译

      进入到源码目录,执行

      ./configure ac_cv_func_malloc_0_nonnull=yes --host=aarch64-none-linux-gnu --enable-static --prefix=/home/feng/文档/development/Linux/application/OK527N/libmodbus-3.1.10/install/
      

      其中--host为交叉编译器的前缀;--prefix为编译结果的目录,需要为绝对路径。之后执行

      make
      make install
      

      编译成功后,就会在install目录下生成三个目录:include、lib、share。我们需要将lib目录移动到开发版的lib目录下

      scp -r ./install/lib/ root@192.168.33.4:/
      

      移植测试程序

      我们这里以random-test-server和random-test-client为例进行测试,其中开发板为server,电脑为client。

      开发板

      首先进入tests目录下,将random-test-server.c测试程序里面的ctx=modbus_new_tcp("127.0.0.1", 1502);
      改为 ctx = modbus_new_tcp(NULL, 1502);,即 server 监控所有的 ip 地址,端口是 1502。之后重新执行交叉编译

      aarch64-none-linux-gnu-gcc -o random-test-server random-test-server.c -L/home/feng/文档/development/Linux/application/OK527N/libmodbus-3.1.10/install/lib -lmodbus -I/home/feng/文档/development/Linux/application/OK527N/libmodbus-3.1.10/install/include/modbus
      

      将得到的random-test-server文件复制到开发板上

      scp -r ./tests/random-test-server root@192.168.33.4:/home
      

      在开发板上执行程序

      chmod 777 random-test-server
      ./random-test-server
      

      电脑端

      编译

      ./configure
      make
      sudo make install
      

      修改测试文件

      首先进入tests目录下,将random-test-client.c测试程序里面的ctx = modbus_new_tcp("127.0.0.1", 1502); 改为 ctx = modbus_new_tcp("192.168.33.4", 1502);,即将服务端的ip地址改为开发板的ip地址,端口是 1502。重新执行make编译

      测试

      首先在开发板上执行./random-test-server启动服务端程序,之后在电脑客户端执行./random-test-client,运行结果如下:
      65ccbe72-63ad-45d4-9eb8-e1b2248e19f2.png

      1c3b3af7-a166-4900-9480-d1097df7b401.png

      1 条回复 最后回复 回复 引用 分享 0
      • 1 / 1
      • First post
        Last post

      Copyright © 2024 深圳全志在线有限公司 粤ICP备2021084185号 粤公网安备44030502007680号

      行为准则 | 用户协议 | 隐私权政策