From b60a1a9622bc09e9c514ce86575c43199f9d3e02 Mon Sep 17 00:00:00 2001 From: "Mr.V" Date: Wed, 20 Mar 2024 13:50:02 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E8=BF=87=E6=BB=A4=E8=BD=A6=E5=A4=B4?= =?UTF-8?q?=E9=80=BB=E8=BE=91bug=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/qt_source/mainwindow.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/qt_source/mainwindow.cpp b/src/qt_source/mainwindow.cpp index bc4bb1e..e4bf1c3 100644 --- a/src/qt_source/mainwindow.cpp +++ b/src/qt_source/mainwindow.cpp @@ -679,14 +679,16 @@ void MainWindow::serialPort_error(QSerialPort::SerialPortError error) void MainWindow::readCom() { try { - QByteArray data = this->serial_->readAll(); // 读取数据 - if(!data.isEmpty()) - { - this->queue_.push(QString(data)); - emit getRfid_signals(); + if (this->serial_->waitForReadyRead(5)) { + QByteArray data = this->serial_->readAll(); // 读取数据 + if(!data.isEmpty()) + { + this->queue_.push(QString(data)); + emit getRfid_signals(); + } + this->serial_->clear(); + data.clear(); } - this->serial_->clear(); - data.clear(); } catch(...) { this->logError("读取串口数据异常!"); } @@ -749,8 +751,7 @@ void MainWindow::getQueueDataThread() { bool isNoCarriage = false; int carT = strTrainInfo.mid(3, 2).simplified().toInt(&isNoCarriage); - isNoCarriage = carT >= 10; - if (isNoCarriage) continue; + if (isNoCarriage && carT >= 10) continue; vecTrain.append(strTrainInfo); int train_order = vecTrain.size(); this->resultTableModel_->setItem(train_order - 1, 0, new QStandardItem(strTrainInfo));