2025-03-13T17:27:30
This commit is contained in:
parent
adca7786c4
commit
d1c95336e1
@ -2,7 +2,8 @@
|
||||
|
||||
Global::Global()
|
||||
{
|
||||
_mode = Global::Mode::ANALYZE;
|
||||
_mode = Global::Mode::Analysis;
|
||||
_deviceConnectStatus = Global::DeviceConnectionStatus::Disconnected;
|
||||
}
|
||||
|
||||
Global *Global::instance()
|
||||
@ -18,3 +19,13 @@ void Global::setMode(const Global::Mode mode)
|
||||
emit sigModeModify(mode);
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
void Global::setDeviceConnectionStatus(const Global::DeviceConnectionStatus status)
|
||||
{
|
||||
if(status != _deviceConnectStatus){
|
||||
_deviceConnectStatus = status;
|
||||
emit sigDeviceConnnectionStatusModify(status);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
19
src/global.h
19
src/global.h
@ -11,16 +11,31 @@ public:
|
||||
static Global* instance();
|
||||
|
||||
enum Mode{
|
||||
EXPERIMENT,
|
||||
ANALYZE
|
||||
Analysis,
|
||||
ConnectedToDev,
|
||||
ExperimentStart
|
||||
};
|
||||
|
||||
|
||||
void setMode(const Mode);
|
||||
Mode getMode(){return _mode;}
|
||||
|
||||
enum DeviceConnectionStatus{
|
||||
Disconnected,
|
||||
Connected
|
||||
};
|
||||
|
||||
#if 0
|
||||
void setDeviceConnectionStatus(const DeviceConnectionStatus);
|
||||
DeviceConnectionStatus getDeviceConnectionStatus(){return _deviceConnectStatus;}
|
||||
#endif
|
||||
signals:
|
||||
void sigModeModify(const Mode);
|
||||
void sigDeviceConnnectionStatusModify(const DeviceConnectionStatus);
|
||||
public slots:
|
||||
private:
|
||||
Mode _mode;
|
||||
DeviceConnectionStatus _deviceConnectStatus;
|
||||
};
|
||||
|
||||
#endif // GLOBAL_H
|
||||
|
@ -2,5 +2,8 @@
|
||||
<qresource prefix="/">
|
||||
<file>images/start.png</file>
|
||||
<file>images/stop.png</file>
|
||||
<file>images/connect.png</file>
|
||||
<file>images/new.png</file>
|
||||
<file>images/real_time_widget.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
BIN
src/images/connect.png
Normal file
BIN
src/images/connect.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
BIN
src/images/new.png
Normal file
BIN
src/images/new.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.5 KiB |
BIN
src/images/real_time_widget.png
Normal file
BIN
src/images/real_time_widget.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.0 KiB |
Binary file not shown.
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 7.4 KiB |
@ -1,7 +1,10 @@
|
||||
#include <qmessagebox.h>
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include "global.h"
|
||||
#include "serialport.h"
|
||||
#include "dataparser.h"
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
@ -9,9 +12,12 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
, _centralWidget(new CentralWidget)
|
||||
,_leftWidget(new LeftWidget)
|
||||
,_expertmentSettingForm(new ExperimentSettingForm)
|
||||
,_realTimeDataForm(new RealTimeDataForm)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
setActionEnable(false);
|
||||
|
||||
this->setToolTip(".....");
|
||||
// resize(2222,1111);
|
||||
|
||||
@ -29,9 +35,6 @@ MainWindow::~MainWindow()
|
||||
void MainWindow::connections()
|
||||
{
|
||||
//ui
|
||||
// connect(ui->actionshitu,&QAction::triggered,
|
||||
// [&]{_expertmentSettingForm->show();});
|
||||
|
||||
connect(_expertmentSettingForm,&ExperimentSettingForm::sigConnectToDevice,
|
||||
SerialPort::instance(),&SerialPort::slotConnectToDevice);
|
||||
//dynamic data
|
||||
@ -42,8 +45,56 @@ void MainWindow::connections()
|
||||
_centralWidget,&CentralWidget::slotModeModify);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_actionstart_triggered()
|
||||
void MainWindow::setActionEnable(const bool flag)
|
||||
{
|
||||
|
||||
if(flag){
|
||||
ui->actionNew->setEnabled(true);
|
||||
ui->actionStart->setEnabled(true);
|
||||
ui->actionStop->setEnabled(true);
|
||||
ui->actionRealTimeWidget->setEnabled(true);
|
||||
}else{
|
||||
ui->actionNew->setEnabled(false);
|
||||
ui->actionStart->setEnabled(false);
|
||||
ui->actionStop->setEnabled(false);
|
||||
ui->actionRealTimeWidget->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_actionStop_triggered()
|
||||
{
|
||||
QByteArray ba = DataParser::setDeviceStartStop(DeviceStartMode::Stop);
|
||||
SerialPort::instance()->slotSendData(ba);
|
||||
SerialPort::instance()->slotCloseSp();
|
||||
}
|
||||
|
||||
void MainWindow::on_actionNew_triggered()
|
||||
{
|
||||
_expertmentSettingForm->show();
|
||||
}
|
||||
|
||||
void MainWindow::on_actionStart_triggered()
|
||||
{
|
||||
QByteArray ba = DataParser::setDeviceStartStop(DeviceStartMode::Start);
|
||||
SerialPort::instance()->slotSendData(ba);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionReadOnly_triggered()
|
||||
{
|
||||
Global::instance()->setMode(Global::Mode::ExperimentStart);
|
||||
SerialPort::instance()->openSp();
|
||||
}
|
||||
|
||||
void MainWindow::on_actionRealTimeWidget_triggered()
|
||||
{
|
||||
_realTimeDataForm->show();
|
||||
}
|
||||
|
||||
void MainWindow::on_actionConnectToDev_triggered()
|
||||
{
|
||||
if(SerialPort::instance()->openSp()){
|
||||
setActionEnable(true);
|
||||
Global::instance()->setMode(Global::Mode::ConnectedToDev);
|
||||
}else{
|
||||
QMessageBox::warning(this, "warnning", "Serial Port open failed.");
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "centralwidget.h"
|
||||
#include "leftwidget.h"
|
||||
#include "experimentsettingform.h"
|
||||
#include "realtimedataform.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui { class MainWindow; }
|
||||
@ -19,14 +20,20 @@ public:
|
||||
MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
private slots:
|
||||
void on_actionstart_triggered();
|
||||
|
||||
void on_actionConnectToDev_triggered();
|
||||
void on_actionNew_triggered();
|
||||
void on_actionStart_triggered();
|
||||
void on_actionStop_triggered();
|
||||
void on_actionReadOnly_triggered();
|
||||
void on_actionRealTimeWidget_triggered();
|
||||
private:
|
||||
void connections();
|
||||
void setActionEnable(const bool);
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
CentralWidget *_centralWidget;
|
||||
LeftWidget*_leftWidget;
|
||||
ExperimentSettingForm *_expertmentSettingForm;
|
||||
RealTimeDataForm* _realTimeDataForm;
|
||||
};
|
||||
#endif // MAINWINDOW_H
|
||||
|
@ -27,13 +27,13 @@
|
||||
<property name="title">
|
||||
<string>文件</string>
|
||||
</property>
|
||||
<addaction name="action_new"/>
|
||||
<addaction name="action22"/>
|
||||
<addaction name="actionNew"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menu_2">
|
||||
<property name="title">
|
||||
<string>视图</string>
|
||||
</property>
|
||||
<addaction name="actionRealTimeWidget"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menu_3">
|
||||
<property name="title">
|
||||
@ -73,8 +73,14 @@
|
||||
<property name="windowTitle">
|
||||
<string>toolBar</string>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>22</width>
|
||||
<height>22</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolButtonStyle">
|
||||
<enum>Qt::ToolButtonIconOnly</enum>
|
||||
<enum>Qt::ToolButtonTextUnderIcon</enum>
|
||||
</property>
|
||||
<attribute name="toolBarArea">
|
||||
<enum>TopToolBarArea</enum>
|
||||
@ -82,25 +88,64 @@
|
||||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<addaction name="actionstart"/>
|
||||
<addaction name="actionConnectToDev"/>
|
||||
<addaction name="actionNew"/>
|
||||
<addaction name="actionStart"/>
|
||||
<addaction name="actionStop"/>
|
||||
<addaction name="actionRealTimeWidget"/>
|
||||
<addaction name="actionReadOnly"/>
|
||||
</widget>
|
||||
<action name="action_new">
|
||||
<action name="actionNew">
|
||||
<property name="icon">
|
||||
<iconset resource="images.qrc">
|
||||
<normaloff>:/images/new.png</normaloff>:/images/new.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>新建</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action22">
|
||||
<property name="text">
|
||||
<string>22</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionstart">
|
||||
<action name="actionStart">
|
||||
<property name="icon">
|
||||
<iconset resource="images.qrc">
|
||||
<normaloff>:/images/start.png</normaloff>:/images/start.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>start</string>
|
||||
<string>开始</string>
|
||||
</property>
|
||||
<property name="visible">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionReadOnly">
|
||||
<property name="text">
|
||||
<string>只读数据</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionStop">
|
||||
<property name="icon">
|
||||
<iconset resource="images.qrc">
|
||||
<normaloff>:/images/stop.png</normaloff>:/images/stop.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>停止</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionRealTimeWidget">
|
||||
<property name="icon">
|
||||
<iconset resource="images.qrc">
|
||||
<normaloff>:/images/real_time_widget.png</normaloff>:/images/real_time_widget.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>实时窗口</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionConnectToDev">
|
||||
<property name="icon">
|
||||
<iconset resource="images.qrc">
|
||||
<normaloff>:/images/connect.png</normaloff>:/images/connect.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>连接设备</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "protocol.h"
|
||||
#include "defines.h"
|
||||
#include "dataparser.h"
|
||||
#include "global.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -94,7 +95,7 @@ void SerialPort::slotReadData()
|
||||
{
|
||||
QByteArray ba = _sp->readAll();
|
||||
|
||||
#if 1
|
||||
#if 0
|
||||
// 将 QByteArray 转换为十六进制字符串
|
||||
QString hexData = ba.toHex(' '); // ' ' 作为分隔符,可选参数
|
||||
qDebug() << "receive info (hex):" << hexData;
|
||||
@ -120,7 +121,9 @@ void SerialPort::slotReadData()
|
||||
QString formattedColdTemp = QString::number(cd.cold_temp, 'f', 3);
|
||||
qDebug() << "cold temp:" << formattedColdTemp;
|
||||
|
||||
emit sigSendCommonData(cd);
|
||||
if(Global::Mode::ExperimentStart == Global::instance()->getMode()){
|
||||
emit sigSendCommonData(cd);
|
||||
}
|
||||
|
||||
#if 0
|
||||
CommonData *serialPortData =
|
||||
@ -137,8 +140,12 @@ void SerialPort::slotReadData()
|
||||
#endif
|
||||
}
|
||||
|
||||
void SerialPort::openSp()
|
||||
bool SerialPort::openSp()
|
||||
{
|
||||
if(_sp != nullptr && _sp->isOpen()){
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts())
|
||||
{
|
||||
u16 pid = info.productIdentifier();
|
||||
@ -154,7 +161,7 @@ void SerialPort::openSp()
|
||||
if (_sp == nullptr)
|
||||
{
|
||||
qDebug() << "Device not found.";
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
// 设置波特率和读写方向
|
||||
@ -173,7 +180,7 @@ void SerialPort::openSp()
|
||||
if (!_sp->open(QIODevice::ReadWrite))
|
||||
{
|
||||
qDebug() << "open failed." << _sp->error();
|
||||
exit(0);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -181,8 +188,10 @@ void SerialPort::openSp()
|
||||
// 设置 DTR 信号为就绪状态(true 表示低电平)
|
||||
_sp->setDataTerminalReady(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void SerialPort::sendCmd(const SerialPort::E_CMD_TYPE e)
|
||||
{
|
||||
#if 1
|
||||
@ -335,7 +344,14 @@ void SerialPort::slotSendData(const QByteArray &ba)
|
||||
{
|
||||
qDebug() << "slotSendData:" << ba.size();
|
||||
|
||||
_sp->write(ba);
|
||||
if(_sp != nullptr && _sp->isOpen()){
|
||||
_sp->write(ba);
|
||||
}else{
|
||||
qDebug()<<"sp not open.";
|
||||
// qErrnoWarning("sp not open.");
|
||||
return;
|
||||
}
|
||||
|
||||
#if 0
|
||||
// 将 QByteArray 转换为十六进制字符串
|
||||
QString hexData = ba.toHex(' '); // ' ' 作为分隔符,可选参数
|
||||
@ -362,5 +378,7 @@ void SerialPort::slotSendData(const QByteArray &ba)
|
||||
|
||||
void SerialPort::slotCloseSp()
|
||||
{
|
||||
_sp->close();
|
||||
if(_sp != nullptr && _sp->isOpen()){
|
||||
_sp->close();
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ public:
|
||||
|
||||
void sendCmd(const E_CMD_TYPE e);
|
||||
static void parserTest();
|
||||
bool openSp();
|
||||
public slots:
|
||||
void slotConnectToDevice(const QByteArray&);
|
||||
void slotSendData(const QByteArray&);
|
||||
@ -34,7 +35,6 @@ protected:
|
||||
private slots:
|
||||
void slotReadData();
|
||||
private:
|
||||
void openSp();
|
||||
void to_hex(char* in_char, int char_length, char* out_char);
|
||||
void displayPortInfo();
|
||||
private:
|
||||
|
@ -36,7 +36,7 @@ CentralWidget::CentralWidget(QWidget *parent)
|
||||
|
||||
void CentralWidget::slotModeModify(const Global::Mode mode)
|
||||
{
|
||||
if (Global::Mode::EXPERIMENT == mode)
|
||||
if (Global::Mode::ExperimentStart == mode)
|
||||
{
|
||||
// 创建画布,设置画布上的点数据
|
||||
_customPlot->addGraph();
|
||||
@ -48,7 +48,7 @@ void CentralWidget::slotModeModify(const Global::Mode mode)
|
||||
_customPlot->xAxis->setRange(0, 400);
|
||||
_customPlot->yAxis->setRange(-20, 20);
|
||||
}
|
||||
else if (Global::Mode::ANALYZE == mode)
|
||||
else if (Global::Mode::Analysis == mode)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -21,12 +21,10 @@ ExperimentSettingForm::ExperimentSettingForm(QWidget *parent) :
|
||||
connect(ui->checkBox_phase_4,&QCheckBox::clicked,
|
||||
this,&ExperimentSettingForm::slotPhase4StateChanged);
|
||||
|
||||
connect(ui->pushButton_connect_to_device,&QPushButton::clicked,
|
||||
this,&ExperimentSettingForm::slotConnectToDevice);
|
||||
// connect(ui->pushButton_connect_to_device,&QPushButton::clicked,
|
||||
// this,&ExperimentSettingForm::slotConnectToDevice);
|
||||
connect(ui->pushButton_cancel,&QPushButton::clicked,
|
||||
this,&ExperimentSettingForm::slotCancel);
|
||||
|
||||
|
||||
}
|
||||
|
||||
ExperimentSettingForm::~ExperimentSettingForm()
|
||||
@ -170,7 +168,7 @@ void ExperimentSettingForm::slotConnectToDevice()
|
||||
qDebug()<<"ba size:"<<ba.size();
|
||||
emit sigConnectToDevice(ba);
|
||||
|
||||
Global::instance()->setMode(Global::Mode::EXPERIMENT);
|
||||
Global::instance()->setMode(Global::Mode::ConnectedToDev);
|
||||
|
||||
#if 0
|
||||
QByteArray startBa = DataParser::setDeviceStartStop(DeviceStartMode::Start);
|
||||
@ -182,7 +180,7 @@ void ExperimentSettingForm::slotConnectToDevice()
|
||||
|
||||
void ExperimentSettingForm::slotCancel()
|
||||
{
|
||||
|
||||
hide();
|
||||
}
|
||||
void ExperimentSettingForm::slotPhaseCheck()
|
||||
{
|
||||
@ -225,4 +223,7 @@ void ExperimentSettingForm::slotPhaseCheck()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ExperimentSettingForm::on_pushButton_connect_to_device_clicked()
|
||||
{
|
||||
slotConnectToDevice();
|
||||
}
|
||||
|
@ -17,6 +17,9 @@ public:
|
||||
|
||||
signals:
|
||||
void sigConnectToDevice(const QByteArray&);
|
||||
private slots:
|
||||
void on_pushButton_connect_to_device_clicked();
|
||||
|
||||
private:
|
||||
void uiReset();
|
||||
//slot
|
||||
|
Loading…
Reference in New Issue
Block a user