2025-10-11T11:07:19
This commit is contained in:
parent
13d2432c71
commit
605bed0ce7
@ -9,7 +9,7 @@ CONFIG+=precompile_header
|
|||||||
PRECOMPILED_HEADER=stable.h
|
PRECOMPILED_HEADER=stable.h
|
||||||
|
|
||||||
#
|
#
|
||||||
VERSION = 1.3.0
|
VERSION = 1.3.4
|
||||||
# 设置目标文件名,包含版本号
|
# 设置目标文件名,包含版本号
|
||||||
TARGET = DSCAnalysisTool_$${VERSION}
|
TARGET = DSCAnalysisTool_$${VERSION}
|
||||||
|
|
||||||
|
|||||||
@ -127,6 +127,8 @@ void MainWindow::connections() {
|
|||||||
connect(SerialPort::instance(), &SerialPort::sigStartExperiment,
|
connect(SerialPort::instance(), &SerialPort::sigStartExperiment,
|
||||||
this, &MainWindow::slotStartExperiment);
|
this, &MainWindow::slotStartExperiment);
|
||||||
|
|
||||||
|
connect(SerialPort::instance(), &SerialPort::sigDeviceDisconnected,
|
||||||
|
this, &MainWindow::slotDeviceDisconnected);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// mode
|
// mode
|
||||||
@ -805,3 +807,19 @@ void MainWindow::showMesgBox(const QString str) {
|
|||||||
isShow = false;
|
isShow = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::slotDeviceDisconnected() {
|
||||||
|
// logde<<"slotDeviceDisconnected...1";
|
||||||
|
// 如果当前是实验模式时,需要先停止实验。
|
||||||
|
if (SerialPort::instance()->isOpen()) {
|
||||||
|
// logde<<"slotDeviceDisconnected...2";
|
||||||
|
// ui更新,断开连接
|
||||||
|
ui->actionConnectToDev->setIcon(QIcon(":/images/connect.png"));
|
||||||
|
ui->actionConnectToDev->setText("连接设备");
|
||||||
|
// 停止实验
|
||||||
|
on_actionStop_triggered();
|
||||||
|
|
||||||
|
SerialPort::instance()->closeSp();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -43,6 +43,8 @@ public slots:
|
|||||||
void slotOITAutoAnalysis(const double,const double);
|
void slotOITAutoAnalysis(const double,const double);
|
||||||
|
|
||||||
void slotStartExperiment();
|
void slotStartExperiment();
|
||||||
|
|
||||||
|
void slotDeviceDisconnected();
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent *event) override;
|
void closeEvent(QCloseEvent *event) override;
|
||||||
private slots:
|
private slots:
|
||||||
|
|||||||
@ -19,7 +19,13 @@ const u16 conVid = 1155; // 0x0483
|
|||||||
const u16 conPid = 22336; // 0x5740
|
const u16 conPid = 22336; // 0x5740
|
||||||
|
|
||||||
SerialPort::SerialPort(QObject *parent)
|
SerialPort::SerialPort(QObject *parent)
|
||||||
: QObject(parent), _sp(new QSerialPort(this)) {
|
: QObject(parent), _sp(new QSerialPort(this)),
|
||||||
|
_portCheckTimer(new QTimer(this)) {
|
||||||
|
//
|
||||||
|
connect(_portCheckTimer, &QTimer::timeout,
|
||||||
|
this, &SerialPort::slotPortCheck);
|
||||||
|
_portCheckTimer->start(1000); // 每秒检测一次
|
||||||
|
|
||||||
// displayPortInfo();
|
// displayPortInfo();
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@ -80,9 +86,13 @@ SerialPort::~SerialPort() {
|
|||||||
logde << "serialport destructor.";
|
logde << "serialport destructor.";
|
||||||
|
|
||||||
closeSp();
|
closeSp();
|
||||||
|
//
|
||||||
delete _sp;
|
delete _sp;
|
||||||
_sp = nullptr;
|
_sp = nullptr;
|
||||||
|
//
|
||||||
|
_portCheckTimer->stop();
|
||||||
|
delete _portCheckTimer;
|
||||||
|
_portCheckTimer = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerialPort::slotReadData() {
|
void SerialPort::slotReadData() {
|
||||||
@ -594,3 +604,22 @@ void SerialPort::slotCloseSp() {
|
|||||||
_sp->close();
|
_sp->close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SerialPort::slotPortCheck() {
|
||||||
|
// logde<<"slotPortCheck...";
|
||||||
|
|
||||||
|
foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) {
|
||||||
|
u16 pid = info.productIdentifier();
|
||||||
|
u16 vid = info.vendorIdentifier();
|
||||||
|
|
||||||
|
if ((pid == conPid) && (vid == conVid)) {
|
||||||
|
// logde<<"slotPortCheck... device connected.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Device disconnected
|
||||||
|
// logde<<"device disconnected.";
|
||||||
|
emit sigDeviceDisconnected();
|
||||||
|
|
||||||
|
// logde<<"slotPortCheck... device disconnected.";
|
||||||
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QSerialPort>
|
#include <QSerialPort>
|
||||||
#include <QSerialPortInfo>
|
#include <QSerialPortInfo>
|
||||||
|
#include <qtimer.h>
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
@ -36,12 +37,14 @@ signals:
|
|||||||
void sigUpdateStatusbarMsg(const QString &);
|
void sigUpdateStatusbarMsg(const QString &);
|
||||||
void sigSaveExperimentalDataMsgBox();
|
void sigSaveExperimentalDataMsgBox();
|
||||||
void sigStartExperiment();
|
void sigStartExperiment();
|
||||||
|
void sigDeviceDisconnected();
|
||||||
public slots:
|
public slots:
|
||||||
void slotDeliverData(const QByteArray &);
|
void slotDeliverData(const QByteArray &);
|
||||||
void slotSendData(const QByteArray &);
|
void slotSendData(const QByteArray &);
|
||||||
void slotCloseSp();
|
void slotCloseSp();
|
||||||
private slots:
|
private slots:
|
||||||
void slotReadData();
|
void slotReadData();
|
||||||
|
void slotPortCheck();
|
||||||
private:
|
private:
|
||||||
void updateStatus(const CommonData &cd);
|
void updateStatus(const CommonData &cd);
|
||||||
void updateAxis();
|
void updateAxis();
|
||||||
@ -52,6 +55,9 @@ private:
|
|||||||
SerialPort(QObject *parent = nullptr);
|
SerialPort(QObject *parent = nullptr);
|
||||||
QSerialPort *_sp;
|
QSerialPort *_sp;
|
||||||
QByteArray _lastWriteBa;
|
QByteArray _lastWriteBa;
|
||||||
|
|
||||||
|
// port check
|
||||||
|
QTimer* _portCheckTimer = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SERIALPORT_H
|
#endif // SERIALPORT_H
|
||||||
Loading…
Reference in New Issue
Block a user