From f8ca76bb316ab02a7f2f2f68ee58eef94bd6d9e5 Mon Sep 17 00:00:00 2001 From: lipengpeng Date: Mon, 4 Aug 2025 11:59:24 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=93=E6=9D=9F=E9=AA=8C=E6=94=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mymodbus.cpp | 5 +++-- serialcommunicator.cpp | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/mymodbus.cpp b/mymodbus.cpp index bd53de6..7cd4289 100644 --- a/mymodbus.cpp +++ b/mymodbus.cpp @@ -202,7 +202,7 @@ QVector MyModbus::analReadCoil() return coil; } - quint8 byteCount = static_cast(receive_[2]); // 数据字节数 + quint8 byteCount = static_cast(receive_.at(2)); // 数据字节数 // 解析每个数据字节 for (int byteIndex = 0; byteIndex < byteCount; byteIndex++) @@ -272,7 +272,8 @@ quint16 MyModbus::calculateCrc(const QByteArray &data) { // 检查最低位 crc = (crc >> 1) ^ polynomial; // 右移并且异或多项式 - } else + } + else { crc >>= 1; // 仅右移 } diff --git a/serialcommunicator.cpp b/serialcommunicator.cpp index a96ed10..8ec40ec 100644 --- a/serialcommunicator.cpp +++ b/serialcommunicator.cpp @@ -154,9 +154,9 @@ void SerialCommunicator::close() resendTimer_->stop(); stationCheck_->stop(); checkTimeOut_->stop(); + emit stationConnect(false); // 清除可能存在的待处理数据 - emit stationConnect(false); serialPort_->clear(); // 关闭串口