2023-09-27 17:30:27 +00:00
|
|
|
|
#include "subform.h"
|
|
|
|
|
#include <ui_sub.h>
|
|
|
|
|
|
|
|
|
|
#include <QSerialPortInfo>
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QMutex>
|
|
|
|
|
#include "Qss.h"
|
|
|
|
|
#include "libmodbus/modbus.h"
|
|
|
|
|
#include <math.h>
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
#include <QFileDialog>
|
|
|
|
|
|
|
|
|
|
#if defined(_MSC_VER) && (_MSC_VER >= 1600)
|
|
|
|
|
# pragma execution_character_set("utf-8")
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
2023-09-30 18:23:57 +00:00
|
|
|
|
SubForm::SubForm(QString addr,int baurate,int device_addr)
|
2023-09-27 17:30:27 +00:00
|
|
|
|
:ui(new Ui::Form) {
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
|
|
init_charts();
|
|
|
|
|
QTimer *pTimer = new QTimer(this);
|
|
|
|
|
QString *com = new QString(addr);
|
|
|
|
|
qDebug()<<*com;
|
2023-09-30 04:06:01 +00:00
|
|
|
|
mModel = new QStandardItemModel(this);
|
|
|
|
|
mModel->setHorizontalHeaderLabels(QStringList() << "<EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ" << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ"<<"<EFBFBD><EFBFBD>ȡʱ<EFBFBD><EFBFBD>");
|
|
|
|
|
ui->tableView->setModel(mModel);
|
2023-10-01 17:54:37 +00:00
|
|
|
|
ui->tableView->setSelectionMode(QAbstractItemView::ContiguousSelection);
|
|
|
|
|
ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
2023-10-01 09:15:57 +00:00
|
|
|
|
mConfig = new Config;
|
|
|
|
|
mConfig->addr = device_addr;
|
|
|
|
|
mConfig->com = *com;
|
2023-10-01 17:54:37 +00:00
|
|
|
|
mConfig->baurate = baurate;
|
2023-10-01 09:15:57 +00:00
|
|
|
|
|
2023-10-02 16:24:09 +00:00
|
|
|
|
connect(pTimer,&QTimer::timeout,[=]() {
|
2023-09-27 17:30:27 +00:00
|
|
|
|
static float sd = 0;
|
|
|
|
|
if(gAsyncData == nullptr)
|
|
|
|
|
return;
|
|
|
|
|
CapData *z = new CapData;
|
|
|
|
|
|
2023-10-01 09:15:57 +00:00
|
|
|
|
int ret = gAsyncData->TakeLast(device_addr,&z);
|
2023-09-27 17:30:27 +00:00
|
|
|
|
if(ret == 0){
|
2023-10-02 16:24:09 +00:00
|
|
|
|
bool succ = z->succ;
|
2023-09-27 17:30:27 +00:00
|
|
|
|
mSeries1->append(sd,z->val1);
|
|
|
|
|
pTime.append(QDateTime::currentDateTime().toString("yyyyMMdd-hh:mm:ss"));
|
|
|
|
|
|
2023-10-01 17:54:37 +00:00
|
|
|
|
QStandardItem *found = nullptr;
|
|
|
|
|
qDebug()<<"mModel->columnCount()"<<mModel->columnCount()
|
|
|
|
|
<<mModel->rowCount();
|
|
|
|
|
int i = 0;
|
|
|
|
|
int j = 0;
|
|
|
|
|
for(;i < mModel->rowCount();i++){
|
|
|
|
|
for(;j < mModel->columnCount();j++){
|
2023-10-02 16:24:09 +00:00
|
|
|
|
if(mModel->item((i,j)) != nullptr){
|
|
|
|
|
qDebug()<<mModel->item((i,j))->data(Qt::DisplayRole);
|
|
|
|
|
if(mModel->item((i,j))->data(Qt::DisplayRole).toInt() == z->addr){
|
|
|
|
|
found = mModel->item((i,j));
|
|
|
|
|
break;
|
|
|
|
|
}
|
2023-10-01 17:54:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(found == 0){
|
2023-10-02 16:24:09 +00:00
|
|
|
|
QStandardItem *item;
|
|
|
|
|
if(succ)
|
|
|
|
|
item = new QStandardItem(QString("%1").arg(z->val1));
|
|
|
|
|
else
|
|
|
|
|
item = new QStandardItem(QString("<EFBFBD><EFBFBD>ʱ"));
|
2023-10-01 17:54:37 +00:00
|
|
|
|
|
2023-10-02 16:24:09 +00:00
|
|
|
|
mModel->setItem(i, 1, item);
|
2023-10-01 17:54:37 +00:00
|
|
|
|
QStandardItem *item1 = new QStandardItem(QString("%1").arg(z->addr));
|
|
|
|
|
mModel->setItem(i, 0, item1);
|
2023-10-02 16:24:09 +00:00
|
|
|
|
mModel->setItem(i, 2, new QStandardItem(QString("%1").arg(z->time)));
|
|
|
|
|
|
2023-10-01 17:54:37 +00:00
|
|
|
|
}else{
|
|
|
|
|
mModel->item(found->row(),0)->setData(QString("%1").arg(z->addr),Qt::DisplayRole);
|
2023-10-02 16:24:09 +00:00
|
|
|
|
if(succ)
|
|
|
|
|
mModel->item(found->row(),1)->setData(QString("%1").arg(z->val1),Qt::DisplayRole);
|
|
|
|
|
else
|
|
|
|
|
mModel->item(found->row(),1)->setData(QString("<EFBFBD><EFBFBD>ʱ"),Qt::DisplayRole);
|
|
|
|
|
mModel->item(found->row(),2)->setData(QString("%1").arg(z->time),Qt::DisplayRole);
|
2023-09-30 04:06:01 +00:00
|
|
|
|
|
2023-10-02 16:24:09 +00:00
|
|
|
|
}
|
2023-09-30 04:06:01 +00:00
|
|
|
|
|
|
|
|
|
|
2023-09-27 17:30:27 +00:00
|
|
|
|
sd ++;
|
|
|
|
|
if(sd > mMaxX){
|
|
|
|
|
mMaxX += 1024;
|
|
|
|
|
mAxisX->setMax(mMaxX);
|
|
|
|
|
}
|
2023-10-02 16:24:09 +00:00
|
|
|
|
delete z;
|
2023-09-27 17:30:27 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
pTimer->start(100);
|
|
|
|
|
qDebug()<<QDateTime::currentDateTime().toString();
|
|
|
|
|
ui->lineEdit_2->setText(addr);
|
2023-10-01 09:15:57 +00:00
|
|
|
|
gAsyncData->AddConfig(this->mConfig);
|
2023-09-27 17:30:27 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SubForm::on_pushButton_clicked() {
|
|
|
|
|
auto mGifFile = QFileDialog::getSaveFileName(this, "",
|
|
|
|
|
QString("%1-%2.csv").arg(ui->lineEdit_2->text())
|
|
|
|
|
.arg(QDateTime::currentDateTime().toString("yyyyMMdd-hhmmss")));
|
|
|
|
|
|
|
|
|
|
if(mGifFile != ""){
|
|
|
|
|
//.csv
|
|
|
|
|
QFile file(mGifFile);
|
|
|
|
|
if(!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
|
|
|
|
{
|
|
|
|
|
qDebug()<<"Cannot open file for writing";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
QTextStream out(&file);
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
out << tr("x,") << tr("error,") << tr("speed,")<< tr("temperature,")<<
|
|
|
|
|
tr("input volate,")<<tr("input current,")<<"motor temperature"<<"\n";
|
|
|
|
|
|
|
|
|
|
for(int i = 0;i < p1.size();i++){
|
|
|
|
|
out <<pTime.at(i).toStdString().c_str()<< ","
|
|
|
|
|
<< p1.at(i)<< "," ;
|
|
|
|
|
out << p2.at(i)<< ",";
|
|
|
|
|
out << p3.at(i)<< ",";
|
|
|
|
|
out << p4.at(i)<< ",";
|
|
|
|
|
out << p5.at(i)<< ",";
|
|
|
|
|
out << p6.at(i)<<"\n";
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
file.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SubForm::init_charts()
|
|
|
|
|
{
|
|
|
|
|
mChart = new QChart();
|
|
|
|
|
mSeries1 = new QLineSeries;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mAxisX = new QValueAxis();
|
|
|
|
|
mAxisY = new QValueAxis();
|
|
|
|
|
mAxisY2 = new QValueAxis();
|
|
|
|
|
|
|
|
|
|
mChart->legend()->hide(); //
|
|
|
|
|
mChart->addSeries(mSeries1); //
|
|
|
|
|
|
|
|
|
|
mAxisX->setMin(0); //YΧ
|
|
|
|
|
mAxisX->setMax(1024);
|
|
|
|
|
mMaxX = 1024;
|
|
|
|
|
mAxisX->setTickCount(17);
|
|
|
|
|
mAxisX->setLabelFormat("%d");
|
|
|
|
|
mAxisX->setTitleText("point"); //X
|
|
|
|
|
mAxisX->setLineVisible(true);
|
|
|
|
|
mAxisX->setGridLinePen(QPen(Qt::white,0.1,Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin));
|
|
|
|
|
mAxisX->setLinePen(QPen(Qt::yellow,1,Qt::SolidLine,Qt::FlatCap,Qt::RoundJoin));
|
|
|
|
|
mAxisX->setLabelsFont(QFont("",8,18,false));
|
|
|
|
|
mAxisX->setLabelsBrush(QBrush(QColor(Qt::white),
|
|
|
|
|
Qt::SolidPattern));
|
|
|
|
|
mAxisX->setLabelsColor(QColor(Qt::white));
|
|
|
|
|
|
|
|
|
|
mAxisY->setMin(-10); //YΧ
|
|
|
|
|
mAxisY->setMax(100);
|
|
|
|
|
mAxisY->setTickCount(11);
|
|
|
|
|
mAxisY->setLabelFormat("%d");
|
|
|
|
|
mAxisY->setLinePenColor(QColor(Qt::yellow)); //
|
|
|
|
|
mAxisY->setGridLineColor(QColor(Qt::yellow));
|
|
|
|
|
mAxisY->setGridLinePen(QPen(Qt::white,0.1,Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin));
|
|
|
|
|
mAxisY->setGridLineVisible(true);
|
|
|
|
|
mAxisY->setLinePen(QPen(Qt::yellow,1,Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin));
|
|
|
|
|
mAxisY->setLabelsFont(QFont("",8,18,false));
|
|
|
|
|
mAxisY->setLabelsBrush(QBrush(QColor(Qt::white),
|
|
|
|
|
Qt::SolidPattern));
|
|
|
|
|
mAxisY->setLabelsColor(QColor(Qt::white));
|
|
|
|
|
mAxisY->setTitleFont(QFont("",13,20,false));
|
|
|
|
|
mAxisY->setTitleBrush(QBrush(QColor(Qt::white),
|
|
|
|
|
Qt::SolidPattern));
|
|
|
|
|
mAxisY->setTitleText("temperature (°C)");
|
|
|
|
|
|
|
|
|
|
mAxisY2->setMin(0); //YΧ
|
|
|
|
|
mAxisY2->setMax(100);
|
|
|
|
|
mAxisY2->setTickCount(11);
|
|
|
|
|
mAxisY2->setLabelFormat("%d");
|
|
|
|
|
mAxisY2->setLinePenColor(QColor(Qt::yellow)); //
|
|
|
|
|
mAxisY2->setGridLineColor(QColor(Qt::yellow));
|
|
|
|
|
mAxisY2->setGridLinePen(QPen(Qt::white,0.1,Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin));
|
|
|
|
|
mAxisY2->setGridLineVisible(true);
|
|
|
|
|
mAxisY2->setLinePen(QPen(Qt::yellow,1,Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin));
|
|
|
|
|
mAxisY2->setLabelsFont(QFont("",8,18,false));
|
|
|
|
|
mAxisY2->setLabelsBrush(QBrush(QColor(Qt::white),
|
|
|
|
|
Qt::SolidPattern));
|
|
|
|
|
mAxisY2->setLabelsColor(QColor(Qt::white));
|
|
|
|
|
mAxisY2->setTitleFont(QFont("",13,20,false));
|
|
|
|
|
mAxisY2->setTitleBrush(QBrush(QColor(Qt::white),
|
|
|
|
|
Qt::SolidPattern));
|
|
|
|
|
mAxisY2->setTitleText("wet %");
|
|
|
|
|
|
|
|
|
|
mChart->addAxis(mAxisX,Qt::AlignBottom); //λmChartеλ
|
|
|
|
|
mChart->addAxis(mAxisY,Qt::AlignLeft);
|
|
|
|
|
mChart->addAxis(mAxisY2,Qt::AlignRight);
|
|
|
|
|
|
|
|
|
|
mChart->setBackgroundVisible(false);
|
|
|
|
|
mSeries1->attachAxis(mAxisX); //
|
|
|
|
|
mSeries1->attachAxis(mAxisY);
|
|
|
|
|
|
|
|
|
|
//mChart
|
|
|
|
|
mChart->setMargins(QMargins(0,0,0,0));
|
|
|
|
|
|
|
|
|
|
ui->graphicsView->setChart(mChart);
|
|
|
|
|
ui->graphicsView->setRenderHint(QPainter::TextAntialiasing); //
|
|
|
|
|
ui->graphicsView->setBackgroundBrush(QBrush(QColor(Qt::black),Qt::SolidPattern));
|
|
|
|
|
ui->graphicsView->scene()->setBackgroundBrush(QBrush(QColor(Qt::black),Qt::SolidPattern));
|
|
|
|
|
ui->graphicsView->setRubberBand(QChartView::VerticalRubberBand);
|
|
|
|
|
|
|
|
|
|
mChart->legend()->setAlignment(Qt::AlignBottom);//
|
|
|
|
|
mChart->legend()->setContentsMargins(10,10,10,10);//left,top,right,bottom
|
|
|
|
|
mChart->legend()->setVisible(true);//
|
|
|
|
|
QFont font = mChart->legend()->font();
|
|
|
|
|
font.setItalic(!font.italic());
|
|
|
|
|
mChart->legend()->setFont(font);//б
|
|
|
|
|
font.setPointSizeF(12);
|
|
|
|
|
mChart->legend()->setFont(font);//С
|
|
|
|
|
mChart->legend()->setFont(QFont(""));//
|
|
|
|
|
mChart->legend()->setLabelColor(Qt::white); //
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SubForm::on_pushButton_2_clicked(bool checked) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SubForm::on_pushButton_2_clicked() {
|
2023-09-30 18:23:57 +00:00
|
|
|
|
for(int i = 0;i < mConfig->req.length();i++){
|
|
|
|
|
if(ui->lineEdit->text().toInt() == mConfig->req[i].addr){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mConfig->req.append(Req{
|
|
|
|
|
ui->lineEdit->text().toUShort(),
|
|
|
|
|
ui->lineEdit_3->text().toUShort(),
|
|
|
|
|
});
|
2023-09-27 17:30:27 +00:00
|
|
|
|
}
|
|
|
|
|
|