# modbus_rtu **Repository Path**: ShadowThreeD/modbus_rtu ## Basic Information - **Project Name**: modbus_rtu - **Description**: example for libmodbus - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-03-21 - **Last Updated**: 2022-03-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README Overview ======== This project is a example for testing libmodbus RTU mode. Both USB-to-serial port and virtual-serial-port can work well by change the device's name. Using by virtual serial port ======== 1. If you don't have enough USB-to-serial port at hands, please execute following cmd to create 2 virtual port: ```bash socat pty,raw,echo=1,link=/home/shadow3d/dev/ttyV1 pty,raw,echo=1,link=/home/shadow3d/dev/ttyV2 > /dev/null 2>&1 & ``` 2. Clone the `modbus_rtu_client` and `modbus_rtu_server` branch; ```bash git clone --branch=modbus_rtu_client https://gitee.com/ShadowThreeD/modbus_rtu.git ./modbus_rtu_client git clone --branch=modbus_rtu_server https://gitee.com/ShadowThreeD/modbus_rtu.git ./modbus_rtu_server ``` 3. Enter modbus_rtu_server and run below command to build the modbus server code: ```bash gcc -Wall ./random-test-server.c ./libmodbus/*.c -o server.out ./server.out ``` 4. Enter modbus_rtu_client and run below command to build the modbus client code: ```bash gcc -Wall ./random-test-client.c ./libmodbus/*.c -o client.out ./client.out ``` 5. You can see "Test: SUCCESS" in client terminal now. Using by USB-to-serial port ==== 1. Clone the `modbus_rtu_client` and `modbus_rtu_server` branch; ```bash git clone --branch=modbus_rtu_client https://gitee.com/ShadowThreeD/modbus_rtu.git ./modbus_rtu_client git clone --branch=modbus_rtu_server https://gitee.com/ShadowThreeD/modbus_rtu.git ./modbus_rtu_server ``` 2. Please modify the device's name to something like `/dev/ttyUSB*` in `random-test-client.c` in `modbus_rtu_client`; 3. Please modify the device's name to something like `/dev/ttyUSB*` in `random-test-server.c` in `modbus_rtu_server`; 4. Enter modbus_rtu_server and run below command to build the modbus server code: ```bash gcc -Wall ./random-test-server.c ./libmodbus/*.c -o server.out ./server.out ``` 5. Enter modbus_rtu_client and run below command to build the modbus client code: ```bash gcc -Wall ./random-test-client.c ./libmodbus/*.c -o client.out ./client.out ``` 6. You can see "Test: SUCCESS" in client terminal now. Git command ===== ```bash git remote add origin https://gitee.com/ShadowThreeD/modbus_rtu.git git push -u origin m1:m2 # push local branch m1 to remote branch m2 git branch --remotes # show remote branch git push -u origin -d modbus_rtu_master # delete remote branch ```