Zzhangyuanhangmodifed:
be054678创建于 2022年2月22日历史提交

libmodbus-xenomai

Description

libmodbus-xenomai is a free software library to send receive data with a device which respects the Modbus protocol

Software Architecture

Software architecture description Unit-test-server and unit-test-client were tested based on Kunpeng920.

Installation

  1. Xenomai build

    ./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 setting

    In xenomai add lo installation directory, the default directory: / usr/xenomai/lib/xenomai/bootstrap. Lo, file content is as follows:

    # 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 build

    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. Test & Result

    Connect the kunpeng920 machine and test machine (virtual machine) with serial port, and then run the unit-test-server and unit-test-client alternately on the test machine and test machine respectively. Unit-test-server and unit-test-client are complete unit test suites. These programs are necessary to test the behavior of the Modbus protocol implementation and libmodbus.

    test machine kunpeng920 machine
    Architecture x86 WMware kunpeng920 arm
    System OpenEuler Centos8
    Kernel 4.19.90 4.19.206
    Test tools libmodbus unit test tools (unit-test-server、unit-test-client) libmodbus unit test tools(unit-test-server、unit-test-client)
    Client run unit-test-server run unit-test-client,ALL PASS
    Server run unit-test-client,ALL PASS run unit-test-server
    Client Test results

    Run unit-test-client at kunpeng920 machine,run unit-test-server at test machine (virtual machine),The test results are as follows:

    unit-test-server

    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><FF><00><8F><59>
    [11][05][01][30][FF][00][8F][59]
    Waiting for an indication...
    <11><01><01><30><00><01><FE><A9>
    [11][01][01][01][94][88]
    Waiting for an indication...
    <11><0F><01><30><00><25><05><CD><6B><B2><0E><1B><CC><C1>
    [11][0F][01][30][00][25][97][73]
    Waiting for an indication...
    <11><01><01><30><00><25><FE><B2>
    [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

    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><FF><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><C2><01><B1><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 Test results

    Run unit-test-server at kunpeng920 machine,run unit-test-client at test machine (virtual machine),The test results are as follows:

    unit-test-server

    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><FF><00><8F><59>
    [11][05][01][30][FF][00][8F][59]
    Waiting for an indication...
    <11><01><01><30><00><01><FE><A9>
    [11][01][01][01][94][88]
    Waiting for an indication...
    <11><0F><01><30><00><25><05><CD><6B><B2><0E><1B><CC><C1>
    [11][0F][01][30][00][25][97][73]
    Waiting for an indication...
    <11><01><01><30><00><25><FE><B2>
    [11][01][05][CD][6B][B2][0E][1B][45][E6]
    Waiting for an indication...
    <11><02><01><C4><00><16><BB><55>
    [11][02][03][AC][DB][35][20][18]
    Waiting for an indication...
    <11><06><01><60><12><34><87><CF>
    [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

    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><FF><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><C2><01><B1><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.
    

Instructions

Xenomai-based libmodbus should be used with the Xenomai RTDM driver!!