diff --git a/AnalysisTool-release/bin/AnalysisTool_0.9.8.2.exe b/AnalysisTool-release/bin/AnalysisTool_0.9.8.2.exe new file mode 100644 index 0000000..eb4f8d2 Binary files /dev/null and b/AnalysisTool-release/bin/AnalysisTool_0.9.8.2.exe differ diff --git a/AnalysisTool-release/bin/log/20250519.log b/AnalysisTool-release/bin/log/20250519.log new file mode 100644 index 0000000..4db1ba7 --- /dev/null +++ b/AnalysisTool-release/bin/log/20250519.log @@ -0,0 +1,3 @@ +[2025-05-19 14:06:15,573] main... +[2025-05-19 14:06:15,573] config config file existed. +[2025-05-19 14:06:15,819] setEventHandlerEnable...0 diff --git a/experiment_data/sample_data/19-6.xlsx b/experiment_data/sample_data/19-6.xlsx new file mode 100644 index 0000000..a7cefc6 Binary files /dev/null and b/experiment_data/sample_data/19-6.xlsx differ diff --git a/experiment_data/sample_data/~$19-6.xlsx b/experiment_data/sample_data/~$19-6.xlsx new file mode 100644 index 0000000..d4a5841 Binary files /dev/null and b/experiment_data/sample_data/~$19-6.xlsx differ diff --git a/src/AnalysisTool.pro b/src/AnalysisTool.pro index bff4d75..04f2bff 100644 --- a/src/AnalysisTool.pro +++ b/src/AnalysisTool.pro @@ -3,13 +3,13 @@ QT += core gui serialport printsupport greaterThan(QT_MAJOR_VERSION, 4): QT += widgets CONFIG += c++11 -#CONFIG += console +CONFIG += console CONFIG+=precompile_header PRECOMPILED_HEADER=stable.h # -VERSION = 0.9.8.1 +VERSION = 0.9.8.3 # 设置目标文件名,包含版本号 TARGET = AnalysisTool_$${VERSION} diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 9a1f2b8..0a9ab9f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -279,6 +279,7 @@ bool MainWindow::saveFile(const QString fileName,const Global::Mode mode) void MainWindow::on_actionStop_triggered() { + logde<<" Stop experiment ..."; if(Global::_mode == Global::Mode::Experiment) { QByteArray ba = DataParser::setDeviceStartStop(DeviceStartMode::Stop); @@ -308,6 +309,8 @@ void MainWindow::on_actionNew_triggered() void MainWindow::on_actionStart_triggered() { + logde<<"start experiment,set soft into experiment mode."; + on_actionClearAllData_triggered(); QByteArray ba = DataParser::setDeviceStartStop(DeviceStartMode::Start); @@ -319,8 +322,6 @@ void MainWindow::on_actionStart_triggered() Global::_mode = Global::Mode::Experiment; - logde<<"start experiment,set soft into experiment mode."; - _manuallyStopTheExperimentFlag = false; } @@ -358,6 +359,8 @@ void MainWindow::slotSaveExperimentalDataMsgBox() void MainWindow::on_actionConnectToDev_triggered() { + logde<<"Connect to device."; + if (SerialPort::instance()->openSp()) { setActionEnable(true); @@ -470,9 +473,9 @@ void MainWindow::on_actionEnthalpyCorrectionSelection_triggered() void MainWindow::on_actionPrintPreview_triggered() { -// _printPreviewForm->setPixmap(_centralWidget->getPixMap()); // _printPreviewForm->show(); + _printPreviewForm->setPixmap(_centralWidget->getPixMap()); _printPreviewForm->_customPrintPreviewDialog->showMaximized(); } diff --git a/src/serialport/dataparser.cpp b/src/serialport/dataparser.cpp index 0747354..5d6d6eb 100644 --- a/src/serialport/dataparser.cpp +++ b/src/serialport/dataparser.cpp @@ -39,7 +39,7 @@ bool commonDataParser(const QByteArray &ba, CommonData &cd) -QByteArray setExperimentInfo(const QVector &vtr) +QByteArray setExperimentInfo(const QVector &vtr,const QByteArray initBa) { // const int phaseLength = sizeof(Phase); const int phaseLength = PHASE_BYTE_SIZE; @@ -60,19 +60,19 @@ QByteArray setExperimentInfo(const QVector &vtr) u16 header = 0x5aa5; memcpy(totalData, (char *)&header, sizeof(u16)); - // totalDataLength +=2; - totalData[2] = 1 + 2 + phaseArrayLength + 2; - // totalDataLength++; + // command + addr + data + crc + totalData[2] = 1 + 2 + phaseArrayLength + 2 + 2; totalData[3] = 0x82; - // totalDataLength++; u16 address = 0x0050; memcpy(totalData + 4, (char *)&address, sizeof(u16)); memcpy(totalData + 6, phaseArray, phaseArrayLength); + memcpy(totalData + 6 + phaseArrayLength,initBa.data(),2); + // char data[300] = {}; @@ -82,13 +82,15 @@ QByteArray setExperimentInfo(const QVector &vtr) memcpy(data + 1, (char *)&address, sizeof(u16)); memcpy(data + 3, phaseArray, phaseArrayLength); + // initial data + memcpy(data + 3 + phaseArrayLength,initBa.data(),2); - u16 crc = modbusCRC16((u8 *)data, 3 + phaseArrayLength); + u16 crc = modbusCRC16((u8 *)data, 3 + phaseArrayLength + 2); // - memcpy(totalData + 6 + phaseArrayLength, (char *)&crc, sizeof(u16)); + memcpy(totalData + 6 + phaseArrayLength + 2, (char *)&crc, sizeof(u16)); - // - return QByteArray(totalData, 6 + phaseArrayLength + 2); + // header + phase data + initial data + crc. + return QByteArray(totalData, 6 + phaseArrayLength + 2 + 2); } QByteArray setDeviceStartStop(const DeviceStartMode mode) diff --git a/src/serialport/dataparser.h b/src/serialport/dataparser.h index 6954ace..1b4a031 100644 --- a/src/serialport/dataparser.h +++ b/src/serialport/dataparser.h @@ -10,7 +10,7 @@ namespace DataParser { -QByteArray setExperimentInfo(const QVector&); +QByteArray setExperimentInfo(const QVector&,const QByteArray initBa); QByteArray inquirePhaseInfo(); QByteArray setDeviceStartStop(const DeviceStartMode); diff --git a/src/serialport/serialport.cpp b/src/serialport/serialport.cpp index 6b0eb58..314869d 100644 --- a/src/serialport/serialport.cpp +++ b/src/serialport/serialport.cpp @@ -140,6 +140,9 @@ void SerialPort::slotReadData() emit sigSendCommonData(cd); } // emit sigSendCommonDataToRealDataForm(cd); + }else{ + QString hexData = ba.toHex(' '); // ' ' 作为分隔符,可选参数 + logde << "receive info (hex):" << hexData.toStdString(); } } } @@ -277,12 +280,10 @@ void SerialPort::commonDataParser(const int dataLength, const u16 addr, switch (mode) { case DeviceStartMode::Stop: - // Global::instance()->setMode(Global::Mode::Analysis); Global::_mode = Global::Mode::Analysis; logde<<"set global mode analysis."; break; case DeviceStartMode::Start: - // Global::instance()->setMode(Global::Mode::ExperimentStart); Global::_mode = Global::Mode::Experiment; break; default: diff --git a/src/serialport/serialport.h b/src/serialport/serialport.h index a9a6347..aba26ef 100644 --- a/src/serialport/serialport.h +++ b/src/serialport/serialport.h @@ -39,7 +39,6 @@ signals: void sigSaveExperimentalDataMsgBox(); public slots: void slotDeliverData(const QByteArray &); - // void slotConnectToDevice(const QByteArray&); void slotSendData(const QByteArray &); void slotCloseSp(); private slots: diff --git a/src/ui/centralwidget.cpp b/src/ui/centralwidget.cpp index 741f873..d644185 100644 --- a/src/ui/centralwidget.cpp +++ b/src/ui/centralwidget.cpp @@ -1087,8 +1087,6 @@ void CentralWidget::loadAnalysisData(const AnalysisMode mode,const double x1,con QString str = QString::number(point.x(),'f',3); drawText(point,str); - // - break; } case AnalysisMode::EndsetTemperaturePoint:{ @@ -1106,6 +1104,8 @@ void CentralWidget::clearAllData() QPixmap CentralWidget::getPixMap() { + _customPlot->replot(); + QApplication::processEvents(); return _customPlot->toPixmap(); } diff --git a/src/ui/centralwidget.h b/src/ui/centralwidget.h index 9d0b713..23007e3 100644 --- a/src/ui/centralwidget.h +++ b/src/ui/centralwidget.h @@ -18,20 +18,6 @@ class CentralWidget:public QWidget { Q_OBJECT public: -#if 0 - enum AnalysisMode{ - Null, - NumericalLabel, - StartPoint, - StopPoint, - PeakSynthesisAnalysis, - GlassTransition, - OnsetTemperaturePoint, - EndsetTemperaturePoint - }; -#endif - -// using AnalysisMode = Global::AnalysisMode; using AnalysisOperation = AnalysisOperationRecorder::AnalysisOperation; using AnalysisMode = AnalysisOperationRecorder::AnalysisMode; @@ -85,7 +71,6 @@ public slots: protected: void timerEvent(QTimerEvent* event); - // void contextMenuEvent(QContextMenuEvent *event); private: void glassTransitionHandle(const double x1,const double x2); void quadraticFit(const QVector& points, double& a, double& b, double& c); diff --git a/src/ui/experimentsettingform.cpp b/src/ui/experimentsettingform.cpp index 066ee08..287d9e8 100644 --- a/src/ui/experimentsettingform.cpp +++ b/src/ui/experimentsettingform.cpp @@ -415,6 +415,7 @@ void ExperimentSettingForm::on_pushButton_deliverData_clicked() ei.sampleWeight = ui->sampleWeightLineEdit->text(); ei.date = ui->dateTimeLineEdit->text(); ei.experimentor = ui->userLineEdit->text(); + #if 0 ei.phaseVtr = phaseVtr; if(ui->radioButton_OIT->isChecked()){ @@ -426,10 +427,22 @@ void ExperimentSettingForm::on_pushButton_deliverData_clicked() ei.initialAtmosPhere = (GasType)(ui->comboBox_phase_1_atmosphere->currentIndex()); #endif + // initial data. + QByteArray initialBa; + if(ui->radioButton_OIT->isChecked()){ + initialBa.append((char)0); + }else{ + initialBa.append((char)1); + } + + char index = ui->comboBox_initial_atmosphere->currentIndex(); + initialBa.append(index); + // - QByteArray ba = DataParser::setExperimentInfo(phaseVtr); + QByteArray ba = DataParser::setExperimentInfo(phaseVtr,initialBa); qDebug() << "ba size:" << ba.size(); + emit sigDeliverData(ba); hide(); } @@ -639,7 +652,6 @@ void ExperimentSettingForm::slotRecvPhaseInfo(const QByteArray &ba) QComboBox *atmoshpereComboBox = qobject_cast(this->findChild(atmoshpereComboBoxName)); if(atmoshpereComboBox){ - qDebug()<<"gas:"<setCurrentIndex(phase.gas % 256); atmoshpereComboBox->setEnabled(true); } @@ -649,30 +661,45 @@ void ExperimentSettingForm::slotRecvPhaseInfo(const QByteArray &ba) // radioButton_OIT // comboBox_initial_atmosphere - u8 *oitValue = data + (ba.size() - 2); + u8 *oitValue = (data + 72); + logde<<"oit value:"<<(int)*oitValue; + if(*oitValue){ + ui->radioButton_OIT->setChecked(false); + ui->radioButton_OIT_not->setChecked(true); +#if 0 QString oitRadioButtonName("radioButton_OIT"); QRadioButton *oitRadioButton = qobject_cast(this->findChild(oitRadioButtonName)); if(oitRadioButton){ oitRadioButton->setChecked(true); } +#endif }else{ + ui->radioButton_OIT->setChecked(true); + ui->radioButton_OIT_not->setChecked(false); +#if 0 QString oitNotRadioButtonName("radioButton_OIT_not"); QRadioButton *oitNotRadioButton = qobject_cast(this->findChild(oitNotRadioButtonName)); if(oitNotRadioButton){ oitNotRadioButton->setChecked(true); } +#endif } - u8 *initAtmosphereValue = data + (ba.size() - 1); + u8 *initAtmosphereValue = (data + 73); + logde<<"initAtmosphereValue:"<< (int)(*initAtmosphereValue); + ui->comboBox_initial_atmosphere->setCurrentIndex((int)*initAtmosphereValue); + +#if 0 QString initialAtmosphereComboBoxObjectName("comboBox_initial_atmosphere"); QComboBox *initialAtmosphereComboBox = qobject_cast(this->findChild(initialAtmosphereComboBoxObjectName)); if(initialAtmosphereComboBox){ initialAtmosphereComboBox->setCurrentIndex(*initAtmosphereValue); } +#endif } diff --git a/src/ui/printpreviewform.cpp b/src/ui/printpreviewform.cpp index cf39814..e29c71c 100644 --- a/src/ui/printpreviewform.cpp +++ b/src/ui/printpreviewform.cpp @@ -2,6 +2,7 @@ #include "printpreviewform.h" #include "ui_printpreviewform.h" +#include "global.h" PrintPreviewForm::PrintPreviewForm(QWidget *parent) : QWidget(parent), @@ -11,7 +12,6 @@ PrintPreviewForm::PrintPreviewForm(QWidget *parent) : { ui->setupUi(this); - _printer->setPageSize(QPageSize(QPageSize::A4)); _printer->setOrientation(QPrinter::Landscape); @@ -19,8 +19,8 @@ PrintPreviewForm::PrintPreviewForm(QWidget *parent) : this,&PrintPreviewForm::slotPaintRequested); _customPrintPreviewDialog->setWindowFlags(_customPrintPreviewDialog->windowFlags() - | Qt::WindowMaximizeButtonHint - | Qt::WindowMinimizeButtonHint); + | Qt::WindowMaximizeButtonHint + | Qt::WindowMinimizeButtonHint); } PrintPreviewForm::~PrintPreviewForm() @@ -30,9 +30,13 @@ PrintPreviewForm::~PrintPreviewForm() void PrintPreviewForm::setPixmap(const QPixmap &pixmap) { +#if 0 QPixmap localPixmap = pixmap; localPixmap.scaled(ui->labelPixmap->size()); ui->labelPixmap->setPixmap(pixmap); +#endif + + _pixmap = pixmap; } @@ -41,6 +45,15 @@ void PrintPreviewForm::slotPaintRequested(QPrinter *printer) printer->setOrientation(QPrinter::Landscape); QPainter painter(printer); +#if 0 + // 重置 painter 状态(清除之前的设置) + painter.resetTransform(); + painter.setPen(Qt::black); + painter.setBrush(Qt::NoBrush); + painter.setOpacity(1.0); +#endif + + // 绘制第一页(不需要先调用 newPage()) // painter.drawText(100, 100, "Page 1"); @@ -49,8 +62,6 @@ void PrintPreviewForm::slotPaintRequested(QPrinter *printer) // painter.drawText(pageRect.width()/2 - 50, 100, "Page 1"); // 居中显示 - - #if 1 // 绘制矩形框 QRect frameRect(50, 50, pageRect.width() - 100, pageRect.height() - 100); @@ -65,13 +76,13 @@ void PrintPreviewForm::slotPaintRequested(QPrinter *printer) // Draw image. QRect imageRect = frameRect; imageRect.setHeight(imageRect.height() - 200); - QPixmap pixmap(":/curve.png"); // 确保这个路径是正确的 - if (!pixmap.isNull()) { + // QPixmap pixmap(":/curve.png"); // 确保这个路径是正确的 + if (!_pixmap.isNull()) { #if 0 QRect pixmapRect = pixmap.rect(); pixmapRect.moveCenter(pageRect.center()); #endif - painter.drawPixmap(imageRect, pixmap); + painter.drawPixmap(imageRect, _pixmap); }else{ qDebug()<<" file not exist"; } @@ -82,16 +93,32 @@ void PrintPreviewForm::slotPaintRequested(QPrinter *printer) painter.drawText(fileInfoRect, Qt::AlignLeft|Qt::AlignVCenter, " Hello, World!"); // Experiment info. + // Only print the first experiment data. QRect experimentRect(frameRect.x(),fileInfoRect.y() + fileInfoRect.height(), 400,frameRect.height() - imageRect.height() - fileInfoRect.height()); painter.drawRect(experimentRect); - QString experimentInfoStr = QString(" 实验员:%1 \n" - " 时间:%2 \n").arg("Jay").arg("20250101"); + Global::ExperimentInfo & exInfo = Global::_curveFileDataVtr.first().ei; + + QString experimentInfoStr = QString(" 样品名称:%1 \n" + " 样品重量:%2 \n" + " 实验日期:%3 \n" + " 实验人员:%4 \n" + ) + .arg(exInfo.sampleName) + .arg(exInfo.sampleWeight) + .arg(exInfo.date) + .arg(exInfo.experimentor); painter.drawText(experimentRect, Qt::AlignLeft|Qt::AlignVCenter, experimentInfoStr); // Phase info. QRect phaseInfoRect(experimentRect.x() + experimentRect.width(),experimentRect.y(), frameRect.width() - experimentRect.width(),experimentRect.height()); + + QVector& phaseTotalVtr = Global::_curveFileDataVtr.first().phaseTotalVtr; + QVector phaseVtr; + for(Global::PhaseTotalInfo& ptInfo:phaseTotalVtr){ + if(ptInfo.) + } QString phaseInfoStr = QString(" 气氛:%1 ; 扫描速率:%2 ; 持续时间:%3 \n").arg("Jay").arg("20250101"); painter.drawText(phaseInfoRect, Qt::AlignLeft|Qt::AlignVCenter, phaseInfoStr); } diff --git a/src/ui/printpreviewform.h b/src/ui/printpreviewform.h index bcceb46..61354a2 100644 --- a/src/ui/printpreviewform.h +++ b/src/ui/printpreviewform.h @@ -25,6 +25,7 @@ private slots: private: Ui::PrintPreviewForm *ui; QPrinter * _printer; + QPixmap _pixmap; }; #endif // PRINTPREVIEWFORM_H