# 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 Based on the code map information provided, I can see this is a Qt-based Modbus RTU Serial Master application. Let me create a comprehensive README.md file for this project: ```markdown # Modbus RTU Serial Master 基于 Qt 的 Modbus RTU 串行主机应用程序,用于通过串口与 Modbus 从设备进行通信。 ## 项目简介 本项目实现了一个 Modbus RTU 串行主机客户端,提供图形界面用于: - 打开/关闭串口连接 - 读取 Modbus 从设备的寄存器数据 - 实时显示通信状态和返回数据 ## 功能特性 - **串口通信**:支持标准串口配置(9600, 19200, 38400, 57600, 115200 等波特率) - **Modbus RTU 协议**:基于 Qt Modbus 库实现标准 RTU 协议 - **寄存器读取**:支持读取不同类型的 Modbus 寄存器 - **图形界面**:直观的 Qt Widgets 界面 - **实时反馈**:显示通信状态和错误信息 ## 系统要求 - Qt 5.15+ 或 Qt 6.x - Qt Modbus 模块 - C++11 编译器 - 支持的操作系统:Windows, Linux, macOS ## 安装说明 ### 从源码编译 1. 确保已安装 Qt 开发环境 2. 克隆项目: ```bash git clone <项目仓库地址> cd modbus ``` 3. 使用 qmake 编译: ```bash qmake modbus.pro make ``` 4. 运行应用: ```bash ./modbus ``` ## 使用说明 ### 1. 打开串口连接 - 在界面中选择正确的串口号 - 配置串口参数(波特率、数据位、停止位、校验位) - 点击"打开"按钮建立连接 ### 2. 读取寄存器数据 - 设置从设备地址(Slave ID) - 选择寄存器类型 - 输入起始寄存器和读取数量 - 点击"读取"按钮获取数据 ### 3. 查看通信结果 - 成功读取的数据显示在界面的数据区域 - 错误信息通过消息框显示 ## 项目结构 ``` modbus/ ├── main.cpp # 应用入口点 ├── MainWindow.h # 主窗口类声明 ├── MainWindow.cpp # 主窗口实现 ├── MainWindow.ui # Qt Designer 界面文件 └── modbus.pro # Qt 项目配置文件 ``` ## 主要类说明 ### MainWindow 主窗口类,管理整个应用程序界面和 Modbus 通信。 **主要方法:** - `read(slaveId, type, reg, qty)` - 读取 Modbus 寄存器 - `on_openPushButton_clicked()` - 处理串口开关 - `on_readPushButton_clicked()` - 处理读取请求 - `readReply(reply)` - 处理读取响应 - `showMessage(msg)` - 显示消息 **成员变量:** - `m_master` - QModbusRtuSerialMaster 实例,用于 Modbus 通信 ## 技术实现 - **通信协议**:Modbus RTU (Remote Terminal Unit) - **通信方式**:串行通信 (RS-232/RS-485) - **Qt 模块**:Qt Core, Qt Widgets, Qt Serial Port, Qt Modbus ## 注意事项 1. 确保串口未被其他应用程序占用 2. 检查 Modbus 从设备的通信参数配置 3. 合理设置超时和重试次数 4. 注意串口线缆的正确连接 ## 许可证 本项目遵循开源许可证协议。 ## 贡献指南 欢迎提交 Issue 和 Pull Request 来改进项目。 ``` This README provides a comprehensive overview of the Modbus RTU Serial Master Qt application, covering: - **Project purpose and features** in Chinese - **System requirements and installation** instructions - **Usage guidelines** with practical steps - **Project structure** and main components - **Technical implementation** details - **Contribution and license** information The documentation is tailored to the Qt-based Modbus application and should help users understand and use the software effectively.