2025-03-13 09:27:31 +00:00
|
|
|
#include <qmessagebox.h>
|
|
|
|
|
|
2025-03-05 09:33:46 +00:00
|
|
|
#include "mainwindow.h"
|
|
|
|
|
#include "ui_mainwindow.h"
|
2025-03-12 09:29:52 +00:00
|
|
|
#include "global.h"
|
|
|
|
|
#include "serialport.h"
|
2025-03-13 09:27:31 +00:00
|
|
|
#include "dataparser.h"
|
2025-03-05 09:33:46 +00:00
|
|
|
|
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
|
|
|
: QMainWindow(parent)
|
|
|
|
|
, ui(new Ui::MainWindow)
|
|
|
|
|
, _centralWidget(new CentralWidget)
|
2025-03-10 09:35:07 +00:00
|
|
|
,_leftWidget(new LeftWidget)
|
2025-03-12 09:29:52 +00:00
|
|
|
,_expertmentSettingForm(new ExperimentSettingForm)
|
2025-03-13 09:27:31 +00:00
|
|
|
,_realTimeDataForm(new RealTimeDataForm)
|
2025-03-05 09:33:46 +00:00
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
2025-03-12 09:29:52 +00:00
|
|
|
|
2025-03-13 09:27:31 +00:00
|
|
|
setActionEnable(false);
|
|
|
|
|
|
2025-03-05 09:33:46 +00:00
|
|
|
this->setToolTip(".....");
|
|
|
|
|
|
|
|
|
|
setCentralWidget(_centralWidget);
|
2025-03-12 09:29:52 +00:00
|
|
|
addDockWidget(Qt::LeftDockWidgetArea, _leftWidget);
|
2025-03-14 08:58:08 +00:00
|
|
|
//
|
|
|
|
|
ui->statusbar->showMessage("showMessage show temp message!");
|
|
|
|
|
// permenent show
|
|
|
|
|
QLabel *permenentLabel = new QLabel(this);
|
|
|
|
|
permenentLabel->setText("Permanent show!");
|
|
|
|
|
ui->statusbar->addPermanentWidget(permenentLabel);
|
|
|
|
|
//
|
2025-03-12 09:29:52 +00:00
|
|
|
connections();
|
2025-03-14 08:58:08 +00:00
|
|
|
//
|
|
|
|
|
_realTimeDataForm->show();
|
2025-03-05 09:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
|
{
|
|
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-12 09:29:52 +00:00
|
|
|
void MainWindow::connections()
|
|
|
|
|
{
|
|
|
|
|
//ui
|
2025-03-17 09:30:54 +00:00
|
|
|
connect(_expertmentSettingForm,&ExperimentSettingForm::sigDeliverData,
|
|
|
|
|
SerialPort::instance(),&SerialPort::slotDeliverData);
|
2025-03-14 08:58:08 +00:00
|
|
|
#if 1
|
2025-03-17 09:30:54 +00:00
|
|
|
//dynamic data
|
2025-03-12 09:29:52 +00:00
|
|
|
connect(SerialPort::instance(),&SerialPort::sigSendCommonData,
|
|
|
|
|
_centralWidget,&CentralWidget::slotRevCommonData);
|
2025-03-14 08:58:08 +00:00
|
|
|
connect(SerialPort::instance(),&SerialPort::sigSendCommonData,
|
|
|
|
|
_realTimeDataForm,&RealTimeDataForm::slotRevCommonData);
|
2025-03-17 09:30:54 +00:00
|
|
|
|
2025-03-14 08:58:08 +00:00
|
|
|
connect(SerialPort::instance(),&SerialPort::sigSendCommonDataToRealDataForm,
|
|
|
|
|
_realTimeDataForm,&RealTimeDataForm::slotRevCommonData);
|
|
|
|
|
#endif
|
|
|
|
|
|
2025-03-12 09:29:52 +00:00
|
|
|
//mode
|
|
|
|
|
connect(Global::instance(),&Global::sigModeModify,
|
|
|
|
|
_centralWidget,&CentralWidget::slotModeModify);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 09:27:31 +00:00
|
|
|
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);
|
2025-03-14 08:58:08 +00:00
|
|
|
// SerialPort::instance()->slotCloseSp();
|
2025-03-13 09:27:31 +00:00
|
|
|
}
|
2025-03-12 09:29:52 +00:00
|
|
|
|
2025-03-13 09:27:31 +00:00
|
|
|
void MainWindow::on_actionNew_triggered()
|
2025-03-12 09:29:52 +00:00
|
|
|
{
|
2025-03-13 09:27:31 +00:00
|
|
|
_expertmentSettingForm->show();
|
|
|
|
|
}
|
2025-03-12 09:29:52 +00:00
|
|
|
|
2025-03-13 09:27:31 +00:00
|
|
|
void MainWindow::on_actionStart_triggered()
|
|
|
|
|
{
|
|
|
|
|
QByteArray ba = DataParser::setDeviceStartStop(DeviceStartMode::Start);
|
2025-03-14 08:58:08 +00:00
|
|
|
|
|
|
|
|
QString hexData = ba.toHex(' '); // ' ' 作为分隔符,可选参数
|
|
|
|
|
qDebug() << "on_actionStart_triggered info (hex):" << hexData;
|
|
|
|
|
|
2025-03-13 09:27:31 +00:00
|
|
|
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()){
|
2025-03-17 09:30:54 +00:00
|
|
|
ui->actionNew->setEnabled(true);
|
2025-03-13 09:27:31 +00:00
|
|
|
Global::instance()->setMode(Global::Mode::ConnectedToDev);
|
|
|
|
|
}else{
|
|
|
|
|
QMessageBox::warning(this, "warnning", "Serial Port open failed.");
|
|
|
|
|
}
|
2025-03-12 09:29:52 +00:00
|
|
|
}
|