添加升级串口打开失败后继续尝试的逻辑。
This commit is contained in:
parent
9d495d487d
commit
928326efb2
@ -13,6 +13,7 @@
|
||||
#include <QProgressBar>
|
||||
#include <QPushButton>
|
||||
#include <QSerialPortInfo>
|
||||
#include <QTimer>
|
||||
#include <QVBoxLayout>
|
||||
#include <filesystem>
|
||||
|
||||
@ -53,7 +54,8 @@ Widget::Widget(QWidget *parent) : QWidget(parent) {
|
||||
setAcceptDrops(true);
|
||||
}
|
||||
|
||||
Widget::~Widget() {}
|
||||
Widget::~Widget() {
|
||||
}
|
||||
|
||||
void Widget::start() {
|
||||
m_progressBar->setValue(0);
|
||||
@ -90,6 +92,9 @@ void Widget::start() {
|
||||
void Widget::onCdcDeviceDiscovered(const QSerialPortInfo &info) {
|
||||
auto status = m_updater->open(info);
|
||||
LOG(info) << "open cdc port: " << info.portName().toStdString() << ", status: " << status;
|
||||
if (!status) {
|
||||
QTimer::singleShot(0, this, [this]() { m_updater->startSearchDevice(); });
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::onSelectButtonClicked() {
|
||||
|
@ -42,9 +42,7 @@ CdcUpdater::~CdcUpdater() {
|
||||
|
||||
void CdcUpdater::start(const QString &path, const QSerialPortInfo &info) {
|
||||
if (info.isNull()) {
|
||||
if (m_timerId < 0) {
|
||||
m_timerId = startTimer(1000);
|
||||
}
|
||||
startSearchDevice();
|
||||
} else {
|
||||
open(info);
|
||||
}
|
||||
@ -54,6 +52,12 @@ void CdcUpdater::start(const QString &path, const QSerialPortInfo &info) {
|
||||
emit progressChanged(++m_progress);
|
||||
}
|
||||
|
||||
void CdcUpdater::startSearchDevice() {
|
||||
if (m_timerId < 0) {
|
||||
m_timerId = startTimer(1000);
|
||||
}
|
||||
}
|
||||
|
||||
bool CdcUpdater::open(const QSerialPortInfo &info) {
|
||||
m_serialPort = std::make_shared<QSerialPort>(info);
|
||||
connect(m_serialPort.get(), &QSerialPort::readyRead, this, &CdcUpdater::onReadyRead);
|
||||
|
@ -37,6 +37,7 @@ public:
|
||||
CdcUpdater(QObject *parent = nullptr);
|
||||
~CdcUpdater();
|
||||
void start(const QString &path, const QSerialPortInfo &info = QSerialPortInfo());
|
||||
void startSearchDevice();
|
||||
bool open(const QSerialPortInfo &info);
|
||||
static std::optional<QSerialPortInfo> searchDevice();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user