From f6579d3ccf9fa7bbe32b2d6f2a764e4931f95607 Mon Sep 17 00:00:00 2001 From: lipengpeng Date: Fri, 25 Jul 2025 17:48:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E5=8A=9F=E8=83=BD=E7=9A=84?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modbus.pro.user | 2 +- widget.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/modbus.pro.user b/modbus.pro.user index a90843a..7a92d7f 100644 --- a/modbus.pro.user +++ b/modbus.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/widget.cpp b/widget.cpp index 3eb3bf1..6cd13fb 100644 --- a/widget.cpp +++ b/widget.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "crc.h" Widget::Widget(QWidget *parent) : @@ -150,6 +151,7 @@ void Widget::on_pushWrite_clicked() ui->textEdit_2->append("发送报文"+SendCommand.toHex().toUpper()); serialPort->write(SendCommand); + Sleep(100); timer.isActive(); timer.start(2000); // 2 s 后触发超时 @@ -202,6 +204,7 @@ void Widget::on_pushWrite_clicked() ui->textEdit_2->append("发送报文"+SendCommand.toHex().toUpper()); serialPort->write(SendCommand); + Sleep(100); timer.isActive(); timer.start(2000); // 2 s 后触发超时 @@ -353,6 +356,7 @@ void Widget::on_btn_read_clicked() { SendCommand.append(0x03); } + SendCommand.append(ui->lineEdit_stratAddress->text().toInt()/256); //加入起始地址 SendCommand.append(ui->lineEdit_stratAddress->text().toInt()%256); SendCommand.append(ui->lineEdit_length->text().toInt()/256); //加入长度 @@ -367,6 +371,7 @@ void Widget::on_btn_read_clicked() ui->textEdit_2->append("发送报文"+SendCommand.toHex().toUpper()); serialPort->write(SendCommand); //发送报文 + Sleep(100); timer.isActive(); timer.start(2000); // 2 s 后触发超时 }