# modbus **Repository Path**: add358/modbus ## Basic Information - **Project Name**: modbus - **Description**: 使用Qt实现的串口Modbus工具示例 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-07-22 - **Last Updated**: 2026-09-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Modbus RTU Serial Master A Qt-based Modbus RTU Serial Master application designed to communicate with Modbus slave devices via serial ports. ## Project Introduction This project implements a Modbus RTU Serial Master client, providing a graphical interface for: - Opening/Closing serial port connections - Reading register data from Modbus slave devices - Displaying communication status and returned data in real-time ## Features - **Serial Communication**: Supports standard serial port configurations (baud rates such as 9600, 19200, 38400, 57600, 115200, etc.) - **Modbus RTU Protocol**: Implements standard RTU protocol based on the Qt Modbus library - **Register Reading**: Supports reading different types of Modbus registers - **Graphical Interface**: Intuitive Qt Widgets interface - **Real-time Feedback**: Displays communication status and error messages ## System Requirements - Qt 5.15+ or Qt 6.x - Qt Modbus module - C++11 compiler - Supported Operating Systems: Windows, Linux, macOS ## Installation Instructions ### Compile from Source 1. Ensure the Qt development environment is installed 2. Clone the project: ```bash git clone cd modbus ``` 3. Compile using qmake: ```bash qmake modbus.pro make ``` 4. Run the application: ```bash ./modbus ``` ## Usage Instructions ### 1. Open Serial Port Connection - Select the correct serial port number in the interface - Configure serial port parameters (Baud Rate, Data Bits, Stop Bits, Parity) - Click the "Open" button to establish the connection ### 2. Read Register Data - Set the Slave ID - Select the register type - Enter the starting register address and quantity to read - Click the "Read" button to retrieve data ### 3. View Communication Results - Successfully read data is displayed in the data area of the interface - Error messages are displayed via message boxes ## Project Structure ``` modbus/ ├── main.cpp # Application entry point ├── MainWindow.h # Main window class declaration ├── MainWindow.cpp # Main window implementation ├── MainWindow.ui # Qt Designer interface file └── modbus.pro # Qt project configuration file ``` ## Main Class Description ### MainWindow The main window class, managing the entire application interface and Modbus communication. **Key Methods:** - `read(slaveId, type, reg, qty)` - Read Modbus registers - `on_openPushButton_clicked()` - Handle serial port toggle - `on_readPushButton_clicked()` - Handle read request - `readReply(reply)` - Handle read response - `showMessage(msg)` - Display message **Member Variables:** - `m_master` - QModbusRtuSerialMaster instance, used for Modbus communication ## Technical Implementation - **Communication Protocol**: Modbus RTU (Remote Terminal Unit) - **Communication Method**: Serial Communication (RS-232/RS-485) - **Qt Modules**: Qt Core, Qt Widgets, Qt Serial Port, Qt Modbus ## Notes 1. Ensure the serial port is not occupied by other applications 2. Check the communication parameter configuration of the Modbus slave device 3. Reasonably set timeout and retry counts 4. Pay attention to the correct connection of serial cables ## License This project follows an open-source license agreement. ## Contribution Guidelines Welcome to submit Issues and Pull Requests to improve the project.