2025-05-19T17:29:21

This commit is contained in:
yuntang 2025-05-19 17:29:21 +08:00
parent b117c5e0be
commit d7443a3e19
15 changed files with 97 additions and 49 deletions

Binary file not shown.

View File

@ -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

Binary file not shown.

Binary file not shown.

View File

@ -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}

View File

@ -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();
}

View File

@ -39,7 +39,7 @@ bool commonDataParser(const QByteArray &ba, CommonData &cd)
QByteArray setExperimentInfo(const QVector<Phase> &vtr)
QByteArray setExperimentInfo(const QVector<Phase> &vtr,const QByteArray initBa)
{
// const int phaseLength = sizeof(Phase);
const int phaseLength = PHASE_BYTE_SIZE;
@ -60,19 +60,19 @@ QByteArray setExperimentInfo(const QVector<Phase> &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<Phase> &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)

View File

@ -10,7 +10,7 @@
namespace DataParser {
QByteArray setExperimentInfo(const QVector<Phase>&);
QByteArray setExperimentInfo(const QVector<Phase>&,const QByteArray initBa);
QByteArray inquirePhaseInfo();
QByteArray setDeviceStartStop(const DeviceStartMode);

View File

@ -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:

View File

@ -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:

View File

@ -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();
}

View File

@ -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<QPointF>& points, double& a, double& b, double& c);

View File

@ -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<QComboBox*>(this->findChild<QObject*>(atmoshpereComboBoxName));
if(atmoshpereComboBox){
qDebug()<<"gas:"<<phase.gas;
atmoshpereComboBox->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<QRadioButton*>(this->findChild<QObject*>(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<QRadioButton*>(this->findChild<QObject*>(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<QComboBox*>(this->findChild<QObject*>(initialAtmosphereComboBoxObjectName));
if(initialAtmosphereComboBox){
initialAtmosphereComboBox->setCurrentIndex(*initAtmosphereValue);
}
#endif
}

View File

@ -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<Global::PhaseTotalInfo>& phaseTotalVtr = Global::_curveFileDataVtr.first().phaseTotalVtr;
QVector<Phase> 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);
}

View File

@ -25,6 +25,7 @@ private slots:
private:
Ui::PrintPreviewForm *ui;
QPrinter * _printer;
QPixmap _pixmap;
};
#endif // PRINTPREVIEWFORM_H