From 757fdcfc21e5f80c63b7b765fe1840c07d440998 Mon Sep 17 00:00:00 2001 From: wh201906 Date: Wed, 23 Nov 2022 16:13:15 +0800 Subject: [PATCH] Misc select available PM3 hardware port when updating the serial port list remove extra empty lines in raw command output by replacing appendPlainText() with insertPlainText() rather than starting the client with QProcess::Text --- src/common/pm3process.cpp | 3 ++- src/ui/mainwindow.cpp | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/common/pm3process.cpp b/src/common/pm3process.cpp index 73ed3fb..19e9012 100644 --- a/src/common/pm3process.cpp +++ b/src/common/pm3process.cpp @@ -28,7 +28,8 @@ void PM3Process::connectPM3(const QString& path, const QStringList args) currArgs = args; // using "-f" option to make the client output flushed after every print. - start(path, args, QProcess::Unbuffered | QProcess::ReadWrite | QProcess::Text); + // single '\r' might appears. Don't use QProcess::Text there or '\r' is ignored. + start(path, args, QProcess::Unbuffered | QProcess::ReadWrite); if(waitForStarted(10000)) { waitForReadyRead(10000); diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index a79bf8c..5ff50e0 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -108,7 +108,8 @@ void MainWindow::on_portSearchTimer_timeout() { QStringList newPortList; // for actural port name QStringList newPortNameList; // for display name -// QStringList portList; + const QString hint = " *"; + foreach(const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) { // qDebug() << info.isNull() << info.portName() << info.description() << info.serialNumber() << info.manufacturer(); @@ -116,7 +117,7 @@ void MainWindow::on_portSearchTimer_timeout() { QString idString = (info.description() + info.serialNumber() + info.manufacturer()).toUpper(); QString portName = info.portName(); - const QString hint = " *"; + newPortList << portName; if(info.hasProductIdentifier() && info.hasVendorIdentifier() && info.vendorIdentifier() == 0x9AC4 && info.productIdentifier() == 0x4B8F) portName += hint; @@ -129,8 +130,15 @@ void MainWindow::on_portSearchTimer_timeout() { portList = newPortList; ui->PM3_portBox->clear(); + int selectId = -1; for(int i = 0; i < portList.size(); i++) + { ui->PM3_portBox->addItem(newPortNameList[i], newPortList[i]); + if(selectId == -1 && newPortNameList[i].endsWith(hint)) + selectId = i; + } + if(selectId != -1) + ui->PM3_portBox->setCurrentIndex(selectId); } } @@ -247,7 +255,8 @@ void MainWindow::on_PM3_disconnectButton_clicked() void MainWindow::refreshOutput(const QString& output) { // qDebug() << "MainWindow::refresh:" << output; - ui->Raw_outputEdit->appendPlainText(output); + ui->Raw_outputEdit->moveCursor(QTextCursor::End); + ui->Raw_outputEdit->insertPlainText(output); ui->Raw_outputEdit->moveCursor(QTextCursor::End); }