# libmodbus-xenomai **Repository Path**: src-openeuler/libmodbus-xenomai ## Basic Information - **Project Name**: libmodbus-xenomai - **Description**: modified libmodbus for xenomai. - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 3 - **Created**: 2021-04-08 - **Last Updated**: 2025-01-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: sig-industrial-control ## README # libmodbus-xenomai #### 介绍 libmodbus-xenomai是一个自由的软件库,它使用一个遵循Modbus协议的设备来发送和接收数据。 #### 软件架构 软件架构说明: 使用 unit-test-server和unit-test-client 基于kunpeng920测试通过; #### 安装教程 1. Xenomai安装 ```shell ./configure --with-pic --with-core=cobalt --enable-smp --disable-tls --enable-dlopen-libs --disable-clock-monotonic-raw make -j`nproc` sudo make install echo ' ### Xenomai export XENOMAI_ROOT_DIR=/usr/xenomai export XENOMAI_PATH=/usr/xenomai export PATH=$PATH:$XENOMAI_PATH/bin:$XENOMAI_PATH/sbin export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$XENOMAI_PATH/lib/pkgconfig export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$XENOMAI_PATH/lib export OROCOS_TARGET=xenomai ' >> ~/.xenomai_rc echo 'source ~/.xenomai_rc' >> ~/.bashrc source ~/.bashrc ``` 2. Xenomai配置 在xenomai 安装目录添加 lo 文件,默认目录:/usr/xenomai/lib/xenomai/bootstrap.lo,文件内容如下: ``` # libbootstrap_pic_la-bootstrap.lo - a libtool object file # Generated by libtool (GNU libtool) 2.4.6 # # Please DO NOT delete this file! # It is necessary for linking the library. # Name of the PIC object. pic_object='bootstrap-pic.o' # Name of the non-PIC object non_pic_object='bootstrap.o' ``` 3. libmodbus编译 ``` apt install autoconf automake libtool ./autogen.sh ./configure --with-gnu-ld --enable-static=yes ac_cv_have_decl_TIOCM_RTS=no make && make install ``` 4. 测试与结果 ​ 使用串口连接kunpeng920机器和测试机器(使用虚机),然后分别在测试机及被测机交替运行,unit-test-server和unit-test-client。unit-test-server和unit-test-client是完整的单元测试套件。 | | 测试机 | kunpeng920 | | :----------: | :----------------------------------------------------------: | :----------------------------------------------------------: | | 硬件架构 | x86 WMware 虚拟机 | kunpeng920 arm物理主机 | | 系统 | OpenEuler | Centos8 | | 内核版本 | 4.19.90 | 4.19.206 | | 测试软件 | libmodbus 源码单元测试工具(unit-test-server、unit-test-client) | libmodbus 源码单元测试工具(unit-test-server、unit-test-client) | | client端测试 | 运行unit-test-server | 运行unit-test-client,结果全部PASS | | server端测试 | 运行unit-test-client,结果全部PASS | 运行unit-test-server | ##### client端测试 ​ 在测试机运行 unit-test-server,kunpeng920 运行 unit-test-client,测试结果如下: unit-test-server ```shell root@localhost:~/libmodbus-3.1.6/tests/.libs# ./unit-test-server rtu Opening /dev/ttyUSB0 at 115200 bauds (N, 8, 1) Waiting for an indication... <11><05><01><30><00><8F><59> [11][05][01][30][FF][00][8F][59] Waiting for an indication... <11><01><01><30><00><01> [11][01][01][01][94][88] Waiting for an indication... <11><0F><01><30><00><25><05><6B><0E><1B> [11][0F][01][30][00][25][97][73] Waiting for an indication... <11><01><01><30><00><25> [11][01][05][CD][6B][B2][0E][1B][45][E6] ... [11][8F][03][05][F4] Waiting for an indication... <11><42><00><00> ERROR CRC received 0x0 != CRC calculated 0x8DD1 Unknown Modbus function code: 0x42 Bytes flushed (0) [11][C2][01][B1][65] Waiting for an indication... ``` unit-test-client ```shell root@localhost:~/libmodbus-3.1.6/tests/.libs# ./unit-test-client rtu Opening /dev/rtdm/rtser0 at 115200 bauds (N, 8, 1) ** UNIT TESTING ** 1/1 No response timeout modification on connect: OK TEST WRITE/READ: [11][05][01][30][FF][00][8F][59] Waiting for a confirmation... <11><05><01><30><00><8F><59> ###### check_confirmation .... finish 1/2 modbus_write_bit: OK [11][01][01][30][00][01][FE][A9] Waiting for a confirmation... <11><01><01><01><94><88> ###### check_confirmation .... finish 2/2 modbus_read_bits: OK ... OK [11][42][00][00][00][00][7B][55] Waiting for a confirmation... <11><01><65> Return an exception on unknown function code: OK TEST INVALID INITIALIZATION: The device string is empty OK The baud rate value must not be zero OK The service string is empty OK ALL TESTS PASS WITH SUCCESS. ``` ##### server端测试 ​ 在测试机运行 unit-test-client,kunpeng920 运行 unit-test-server,测试结果如下: unit-test-server ```shell root@localhost:~/libmodbus-3.1.6/tests/.libs# ./unit-test-server rtu Opening /dev/rtdm/rtser0 at 115200 bauds (N, 8, 1) loop test start ... Waiting for an indication... <11><05><01><30><00><8F><59> [11][05][01][30][FF][00][8F][59] Waiting for an indication... <11><01><01><30><00><01> [11][01][01][01][94][88] Waiting for an indication... <11><0F><01><30><00><25><05><6B><0E><1B> [11][0F][01][30][00][25][97][73] Waiting for an indication... <11><01><01><30><00><25> [11][01][05][CD][6B][B2][0E][1B][45][E6] Waiting for an indication... <11><02><01><00><16><55> [11][02][03][AC][DB][35][20][18] Waiting for an indication... <11><06><01><60><12><34><87> [11][06][01][60][12][34][87][CF] ... Bytes flushed (0) [11][8F][03][05][F4] Waiting for an indication... <11><42><00><00> ERROR CRC received 0x0 != CRC calculated 0x8DD1 Unknown Modbus function code: 0x42 Bytes flushed (0) [11][C2][01][B1][65] Waiting for an indication... ``` unit-test-client ```shell root@localhost:~/libmodbus-3.1.6/tests/.libs# ./unit-test-client rtu Opening /dev/ttyUSB0 at 115200 bauds (N, 8, 1) ** UNIT TESTING ** 1/1 No response timeout modification on connect: OK TEST WRITE/READ: [11][05][01][30][FF][00][8F][59] Waiting for a confirmation... <11><05><01><30><00><8F><59> 1/2 modbus_write_bit: OK [11][01][01][30][00][01][FE][A9] Waiting for a confirmation... <11><01><01><01><94><88> 2/2 modbus_read_bits: OK ... OK [11][42][00][00][00][00][7B][55] Waiting for a confirmation... <11><01><65> Return an exception on unknown function code: OK TEST INVALID INITIALIZATION: The device string is empty OK The baud rate value must not be zero OK The service string is empty OK ALL TESTS PASS WITH SUCCESS. ``` #### 使用说明 基于Xenomai编译的libmodbus要与Xenomai RTDM驱动一起使用!!!