Compare commits
10 Commits
old_versio
...
develop
Author | SHA1 | Date |
---|---|---|
|
a13d1e4a98 | |
|
525d6adb0c | |
|
2e7e92e4da | |
|
25f0c01a47 | |
|
8279590f38 | |
|
27f3def00a | |
|
bfee5f9d49 | |
|
d4ae45d1dc | |
|
d36da2f3ce | |
|
f474423549 |
|
@ -11,6 +11,7 @@ CONFIG += c++17
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
appproto.cpp \
|
appproto.cpp \
|
||||||
|
appproto_english.cpp \
|
||||||
batt.cpp \
|
batt.cpp \
|
||||||
chartpaint.cpp \
|
chartpaint.cpp \
|
||||||
custom/delegate.cpp \
|
custom/delegate.cpp \
|
||||||
|
@ -23,10 +24,13 @@ SOURCES += \
|
||||||
mainwindow.cpp \
|
mainwindow.cpp \
|
||||||
modbusrtu.cpp \
|
modbusrtu.cpp \
|
||||||
proto/battery.pb.cc \
|
proto/battery.pb.cc \
|
||||||
appserial.cpp
|
appserial.cpp \
|
||||||
|
proto/battery_english.pb.cc \
|
||||||
|
upgradeicon.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
appproto.h \
|
appproto.h \
|
||||||
|
appproto_english.h \
|
||||||
batt.h \
|
batt.h \
|
||||||
chartpaint.h \
|
chartpaint.h \
|
||||||
custom/delegate.h \
|
custom/delegate.h \
|
||||||
|
@ -42,7 +46,9 @@ HEADERS += \
|
||||||
mainwindow.h \
|
mainwindow.h \
|
||||||
modbusrtu.h \
|
modbusrtu.h \
|
||||||
proto/battery.pb.h \
|
proto/battery.pb.h \
|
||||||
appserial.h
|
appserial.h \
|
||||||
|
proto/battery_english.pb.h \
|
||||||
|
upgradeicon.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
dialoglogin.ui \
|
dialoglogin.ui \
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 23 KiB |
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
Binary file not shown.
Binary file not shown.
|
@ -1,2 +1,3 @@
|
||||||
# battery_monitor
|
# battery_monitor
|
||||||
|
## Version1.0.0 very smooth!
|
||||||
|
|
||||||
|
|
32
appproto.cpp
32
appproto.cpp
|
@ -15,38 +15,6 @@ AppProto::~AppProto()
|
||||||
|
|
||||||
void AppProto::init()
|
void AppProto::init()
|
||||||
{
|
{
|
||||||
// Battery::BCUList bcus;
|
|
||||||
// std::ifstream finBetteryData("battery.data", std::ios::binary);
|
|
||||||
// if(!bcus.ParseFromIstream(&finBetteryData)) {
|
|
||||||
// qDebug() << "Failed to parse BSU message.";
|
|
||||||
// // config message
|
|
||||||
// int bmuNum = 16;
|
|
||||||
// int cellNum = 26;
|
|
||||||
// for(int i = 0; i < bmuNum; i++) {
|
|
||||||
// bcus.add_bmus();
|
|
||||||
// bcus.mutable_bmus(i)->set_name("BUM" + QString("%1").arg(i+1).toStdString());
|
|
||||||
// for(int j = 0; j < cellNum; j++) {
|
|
||||||
// bcus.mutable_bmus(i)->add_cells();
|
|
||||||
// bcus.mutable_bmus(i)->mutable_cells(j)->set_name("Cell" + QString("%1").arg(j+1).toStdString());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// std::fstream foutBetteryData("battery.data",std::ios::out | std::ios::trunc | std::ios::binary);
|
|
||||||
// if(!bcus.SerializePartialToOstream(&foutBetteryData)) {
|
|
||||||
// qDebug() << "filed";
|
|
||||||
// }
|
|
||||||
// foutBetteryData.close();
|
|
||||||
// foutBetteryData.clear();
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// qDebug() << "bum num:" << bcus.bmus_size();
|
|
||||||
// for(int i = 0; i < bcus.bmus_size(); i++) {
|
|
||||||
// qDebug() << "bmu name:" << bcus.bmus(i).name().c_str() << "cell num:" << bcus.bmus(i).cells_size();
|
|
||||||
// for(int j = 0; j < bcus.bmus(i).cells_size(); j++) {
|
|
||||||
// qDebug() << "cell name:" << bcus.bmus(i).cells(j).name().c_str();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
BatteryConfig::Item item;
|
BatteryConfig::Item item;
|
||||||
std::ifstream finBetteryData("battery.data", std::ios::binary);
|
std::ifstream finBetteryData("battery.data", std::ios::binary);
|
||||||
if(!item.ParseFromIstream(&finBetteryData)) {
|
if(!item.ParseFromIstream(&finBetteryData)) {
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,30 @@
|
||||||
|
#ifndef APPPROTO_ENGLISH_H
|
||||||
|
#define APPPROTO_ENGLISH_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class Appproto_English : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit Appproto_English(QObject *parent = nullptr);
|
||||||
|
~Appproto_English();
|
||||||
|
|
||||||
|
void init();
|
||||||
|
|
||||||
|
public:
|
||||||
|
int itemCount = 0;
|
||||||
|
int itemCount_balance = 0;
|
||||||
|
int itemCount_DIDO = 0;
|
||||||
|
int itemCount_SOX = 0;
|
||||||
|
int itemCount_other = 0;
|
||||||
|
int itemCount_alert_value = 0;
|
||||||
|
int itemCount_alert_delay = 0;
|
||||||
|
int itemCount_alert_release_value = 0;
|
||||||
|
int itemCount_alert_release_delay = 0;
|
||||||
|
int itemCount_alert_dropcurr_rate = 0;
|
||||||
|
int itemCount_alert_solve_measure = 0;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // APPPROTO_ENGLISH_H
|
|
@ -13,6 +13,7 @@
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
#include <QLabel>
|
||||||
#include <QTableView>
|
#include <QTableView>
|
||||||
Delegate::Delegate(QObject *parent): QStyledItemDelegate(parent)
|
Delegate::Delegate(QObject *parent): QStyledItemDelegate(parent)
|
||||||
{
|
{
|
||||||
|
@ -81,9 +82,16 @@ QWidget *Delegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/*o
|
||||||
else if (delegateType == "QLineEdit")
|
else if (delegateType == "QLineEdit")
|
||||||
{
|
{
|
||||||
QLineEdit *lineEidt = new QLineEdit(parent);
|
QLineEdit *lineEidt = new QLineEdit(parent);
|
||||||
|
// lineEidt->setReadOnly(true);
|
||||||
editor = lineEidt;
|
editor = lineEidt;
|
||||||
connect(lineEidt, SIGNAL(textChanged(QString)), this, SLOT(on_valueChanged(QString)));
|
connect(lineEidt, SIGNAL(textChanged(QString)), this, SLOT(on_valueChanged(QString)));
|
||||||
}
|
}
|
||||||
|
else if (delegateType == "QLabel")
|
||||||
|
{
|
||||||
|
QLabel *label = new QLabel(parent);
|
||||||
|
editor = label;
|
||||||
|
connect(label, SIGNAL(textChanged(QString)), this, SLOT(on_valueChanged(QString)));
|
||||||
|
}
|
||||||
|
|
||||||
return editor;
|
return editor;
|
||||||
}
|
}
|
||||||
|
@ -126,6 +134,11 @@ void Delegate::setEditorData(QWidget *editor, const QModelIndex &index) const
|
||||||
QLineEdit *lineEidt = static_cast<QLineEdit *>(editor);
|
QLineEdit *lineEidt = static_cast<QLineEdit *>(editor);
|
||||||
lineEidt->setText(value.toString());
|
lineEidt->setText(value.toString());
|
||||||
}
|
}
|
||||||
|
else if (delegateType == "QLabel")
|
||||||
|
{
|
||||||
|
QLabel *label = static_cast<QLabel *>(editor);
|
||||||
|
label->setText(value.toString());
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QStyledItemDelegate::setEditorData(editor, index);
|
QStyledItemDelegate::setEditorData(editor, index);
|
||||||
|
@ -171,6 +184,11 @@ void Delegate::setModelData(QWidget *editor, QAbstractItemModel *model,
|
||||||
QLineEdit *lineEidt = static_cast<QLineEdit *>(editor);
|
QLineEdit *lineEidt = static_cast<QLineEdit *>(editor);
|
||||||
value = lineEidt->text();
|
value = lineEidt->text();
|
||||||
}
|
}
|
||||||
|
else if (delegateType == "QLabel")
|
||||||
|
{
|
||||||
|
QLabel *label = static_cast<QLabel *>(editor);
|
||||||
|
value = label->text();
|
||||||
|
}
|
||||||
model->setData(index, value, Qt::EditRole);
|
model->setData(index, value, Qt::EditRole);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -208,6 +226,7 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons
|
||||||
drawLineEdit(painter, option, index);
|
drawLineEdit(painter, option, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}//if
|
}//if
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
136
dialoglogin.cpp
136
dialoglogin.cpp
|
@ -10,12 +10,16 @@
|
||||||
#include "appserial.h"
|
#include "appserial.h"
|
||||||
#include "modbusrtu.h"
|
#include "modbusrtu.h"
|
||||||
#include <windef.h>
|
#include <windef.h>
|
||||||
|
#include <QTranslator>
|
||||||
|
#include <QThread>
|
||||||
|
#include <QMetaType>
|
||||||
|
|
||||||
DialogLogin::DialogLogin(QWidget *parent)
|
DialogLogin::DialogLogin(QWidget *parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
, ui(new Ui::DialogLogin)
|
, ui(new Ui::DialogLogin)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
qRegisterMetaType<QList<int>>("QList<int>");
|
||||||
init();
|
init();
|
||||||
serialInit();
|
serialInit();
|
||||||
mainwindowInit();
|
mainwindowInit();
|
||||||
|
@ -52,6 +56,15 @@ void DialogLogin::init()
|
||||||
ini = new QSettings("config.ini", QSettings::IniFormat);
|
ini = new QSettings("config.ini", QSettings::IniFormat);
|
||||||
connect(ui->btnConnect, &QPushButton::clicked, this, &DialogLogin::slot_btnConnect_clicked);
|
connect(ui->btnConnect, &QPushButton::clicked, this, &DialogLogin::slot_btnConnect_clicked);
|
||||||
|
|
||||||
|
ui->groupBox->setStyleSheet("QGroupBox { border: none; }");
|
||||||
|
|
||||||
|
ui->label_bluesunLogo->setStyleSheet("QLabel { background-image: url(:/Image/bluesun.png); "
|
||||||
|
"background-repeat: no-repeat; background-size: cover; background-position: center center;}");
|
||||||
|
// //将背景设置为白色
|
||||||
|
// ui->groupBox->setStyleSheet("background-color: #FFFFFF;");
|
||||||
|
|
||||||
|
m_MainWindow->setStyleSheet("background-color: #FFFFFF;");
|
||||||
|
|
||||||
// //传递BCU个数的信号与槽
|
// //传递BCU个数的信号与槽
|
||||||
// BCUNumbers = ui->comboBoxBCUQuantity->currentText().toInt();
|
// BCUNumbers = ui->comboBoxBCUQuantity->currentText().toInt();
|
||||||
// qDebug() << "the number of the BCU: " << BCUNumbers;
|
// qDebug() << "the number of the BCU: " << BCUNumbers;
|
||||||
|
@ -89,6 +102,42 @@ void DialogLogin::init()
|
||||||
//读寄存器的信号与槽的连接
|
//读寄存器的信号与槽的连接
|
||||||
connect(m_MainWindow, &MainWindow::read_regs_signals, m_ModbusRTU, &ModbusRTU::read_regs_slot);
|
connect(m_MainWindow, &MainWindow::read_regs_signals, m_ModbusRTU, &ModbusRTU::read_regs_slot);
|
||||||
connect(m_ModbusRTU, &ModbusRTU::sig_showReadHoldingRegs, m_MainWindow, &MainWindow::slot_pageParaSetShow);
|
connect(m_ModbusRTU, &ModbusRTU::sig_showReadHoldingRegs, m_MainWindow, &MainWindow::slot_pageParaSetShow);
|
||||||
|
|
||||||
|
//主窗口关闭时,关闭线程
|
||||||
|
connect(m_MainWindow, &MainWindow::quitThread, this, [=]{
|
||||||
|
qDebug() << "关闭线程";
|
||||||
|
m_ModbusRTU->quit();
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(m_MainWindow, &MainWindow::closeThread, m_ModbusRTU, &ModbusRTU::slot_pauseThread);
|
||||||
|
|
||||||
|
connect(m_MainWindow, &MainWindow::openThread, m_ModbusRTU, &ModbusRTU::slot_resumeThread);
|
||||||
|
|
||||||
|
// ui->btnConnect->setStyleSheet("QPushButton { background-color: lightgray; color: black; border: none; }");
|
||||||
|
|
||||||
|
//主窗口接受语言选择number的信号与槽的连接
|
||||||
|
connect(this, &DialogLogin::sendLanNumberSignals, m_MainWindow, &MainWindow::getLanNumberSlot);
|
||||||
|
|
||||||
|
//故障解析的信号与槽
|
||||||
|
connect(m_ModbusRTU, &ModbusRTU::sig_showFault, m_MainWindow, &MainWindow::slot_pageHomeFault);
|
||||||
|
|
||||||
|
//电池界面中,点击bmu发送对应的数据
|
||||||
|
// connect(m_MainWindow, &MainWindow::read_regs_input_signals_vol, m_ModbusRTU, &ModbusRTU::read_regs_input_slot_vol);
|
||||||
|
// connect(m_MainWindow, &MainWindow::read_regs_input_signals_temp, m_ModbusRTU, &ModbusRTU::read_regs_input_slot_temp);
|
||||||
|
|
||||||
|
//上面的方法太low了,直接将row的索引传到modbus的线程中去
|
||||||
|
connect(m_MainWindow, &MainWindow::row_of_bmus_index, m_ModbusRTU, &ModbusRTU::change_BMUIndex_slot);
|
||||||
|
|
||||||
|
|
||||||
|
// ui->btnConnect->setStyleSheet("QPushButton { background-color: #87CEFA; color: white; }"
|
||||||
|
// "QPushButton:hover { background-color: #77B5D6; color: white; }");
|
||||||
|
|
||||||
|
// QMetaObject::invokeMethod(m_ModbusRTU,"read_regs_slot",Qt::QueuedConnection);
|
||||||
|
// connect(m_ModbusRTU, &ModbusRTU::sig_readMoveToThread, m_ModbusRTU, &ModbusRTU::read_regs_slot, Qt::QueuedConnection);
|
||||||
|
// thread = new QThread;
|
||||||
|
|
||||||
|
// m_ModbusRTU->moveToThread(thread);
|
||||||
|
// thread->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DialogLogin::serialInit()
|
void DialogLogin::serialInit()
|
||||||
|
@ -103,6 +152,8 @@ void DialogLogin::serialInit()
|
||||||
ui->comboBoxDataBits->setCurrentIndex(3);
|
ui->comboBoxDataBits->setCurrentIndex(3);
|
||||||
ui->comboBoxStopBits->setCurrentIndex(0);
|
ui->comboBoxStopBits->setCurrentIndex(0);
|
||||||
ui->comboBoxParity->setCurrentIndex(0);
|
ui->comboBoxParity->setCurrentIndex(0);
|
||||||
|
ui->comboBoxLanguage->setCurrentIndex(ini->value("System/Language").toUInt());
|
||||||
|
// qDebug() << "lan currentIndex false:" << ini->value("System/Language").toUInt();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ui->comboBoxSerialPort->addItems(m_Serial->getAvailablePort());
|
ui->comboBoxSerialPort->addItems(m_Serial->getAvailablePort());
|
||||||
|
@ -110,6 +161,9 @@ void DialogLogin::serialInit()
|
||||||
ui->comboBoxDataBits->setCurrentIndex(ini->value("Serial/DataBits").toUInt());
|
ui->comboBoxDataBits->setCurrentIndex(ini->value("Serial/DataBits").toUInt());
|
||||||
ui->comboBoxStopBits->setCurrentIndex(ini->value("Serial/StopBits").toUInt());
|
ui->comboBoxStopBits->setCurrentIndex(ini->value("Serial/StopBits").toUInt());
|
||||||
ui->comboBoxParity->setCurrentIndex(ini->value("Serial/Parity").toUInt());
|
ui->comboBoxParity->setCurrentIndex(ini->value("Serial/Parity").toUInt());
|
||||||
|
ui->comboBoxLanguage->setCurrentIndex(ini->value("System/Language").toUInt());
|
||||||
|
// ui->comboBoxLanguage->setCurrentIndex(ini->value());
|
||||||
|
// qDebug() << "lan currentIndex " << ini->value("System/Language").toUInt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,29 +177,29 @@ void DialogLogin::mainwindowInit()
|
||||||
connect(m_MainWindow, &MainWindow::showLogin, this, [=]{
|
connect(m_MainWindow, &MainWindow::showLogin, this, [=]{
|
||||||
this->show();
|
this->show();
|
||||||
});
|
});
|
||||||
connect(this, &DialogLogin::finished, m_MainWindow, [=]{
|
// connect(this, &DialogLogin::finished, m_MainWindow, [=]{
|
||||||
m_MainWindow->ui->btnSetup->setStyleSheet("#btnSetup{"
|
// m_MainWindow->ui->btnSetup->setStyleSheet("#btnSetup{"
|
||||||
"background-image: url(:/Image/advance-set-line.png);"
|
// "background-image: url(:/Image/advance-set-line.png);"
|
||||||
"background-repeat: no-repeat;"
|
// "background-repeat: no-repeat;"
|
||||||
"background-position: center;"
|
// "background-position: center;"
|
||||||
"background-color: rgba(255, 255, 255, 0);"
|
// "background-color: rgba(255, 255, 255, 0);"
|
||||||
"}"
|
// "}"
|
||||||
"#btnSetup::hover{"
|
// "#btnSetup::hover{"
|
||||||
"background-image: url(:/Image/advance-set-line1.png);"
|
// "background-image: url(:/Image/advance-set-line1.png);"
|
||||||
"background-repeat: no-repeat;"
|
// "background-repeat: no-repeat;"
|
||||||
"background-position: center;"
|
// "background-position: center;"
|
||||||
"background-color: rgba(255, 255, 255, 0);"
|
// "background-color: rgba(255, 255, 255, 0);"
|
||||||
"}");
|
// "}");
|
||||||
});
|
// });
|
||||||
connect(m_MainWindow->ui->btnSetup, &QPushButton::pressed, this, [=]{
|
// connect(m_MainWindow->ui->btnSetup, &QPushButton::pressed, this, [=]{
|
||||||
qDebug() << __FUNCTION__ << "disconnected";
|
// qDebug() << __FUNCTION__ << "disconnected";
|
||||||
m_ModbusRTU->isConnect = false;
|
// m_ModbusRTU->isConnect = false;
|
||||||
m_MainWindow->statusBarConnectedIcon->setPixmap(QPixmap(QIcon(":/Image/connected1.png").pixmap(QSize(24, 24))));
|
// m_MainWindow->statusBarConnectedIcon->setPixmap(QPixmap(QIcon(":/Image/connected1.png").pixmap(QSize(24, 24))));
|
||||||
m_Serial->m_SerialPort->close();
|
// m_Serial->m_SerialPort->close();
|
||||||
m_ModbusRTU->modbusRTUDisconnect();
|
// m_ModbusRTU->modbusRTUDisconnect();
|
||||||
ui->comboBoxSerialPort->clear();
|
// ui->comboBoxSerialPort->clear();
|
||||||
ui->comboBoxSerialPort->addItems(m_Serial->getAvailablePort());
|
// ui->comboBoxSerialPort->addItems(m_Serial->getAvailablePort());
|
||||||
});
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
void DialogLogin::slot_comChangeStatus(QString name, bool flag)
|
void DialogLogin::slot_comChangeStatus(QString name, bool flag)
|
||||||
|
@ -158,14 +212,40 @@ void DialogLogin::slot_comChangeStatus(QString name, bool flag)
|
||||||
|
|
||||||
void DialogLogin::slot_btnConnect_clicked()
|
void DialogLogin::slot_btnConnect_clicked()
|
||||||
{
|
{
|
||||||
BCUNumbers = ui->comboBoxBCUQuantity->currentText().toInt();
|
|
||||||
emit sendBCUNumberSignals(BCUNumbers);
|
|
||||||
connect(this, &DialogLogin::sendBCUNumberSignals, m_MainWindow, &MainWindow::slot_getBcuNumberFromDialoglogin);
|
|
||||||
ini->setValue("Serial/BaudRate", ui->comboBoxBaudRate->currentIndex());
|
ini->setValue("Serial/BaudRate", ui->comboBoxBaudRate->currentIndex());
|
||||||
ini->setValue("Serial/DataBits", ui->comboBoxDataBits->currentIndex());
|
ini->setValue("Serial/DataBits", ui->comboBoxDataBits->currentIndex());
|
||||||
ini->setValue("Serial/StopBits", ui->comboBoxStopBits->currentIndex());
|
ini->setValue("Serial/StopBits", ui->comboBoxStopBits->currentIndex());
|
||||||
ini->setValue("Serial/Parity", ui->comboBoxParity->currentIndex());
|
ini->setValue("Serial/Parity", ui->comboBoxParity->currentIndex());
|
||||||
ini->sync();
|
ini->sync();
|
||||||
|
// BCUNumbers = ui->comboBoxBCUQuantity->currentText().toInt();
|
||||||
|
|
||||||
|
QString language = ui->comboBoxLanguage->currentText();
|
||||||
|
if (language == "English")
|
||||||
|
{
|
||||||
|
qDebug() << "ini lanuage index" << ini->value("System/Language");
|
||||||
|
ini->setValue("System/Language", 1);
|
||||||
|
ini->sync();
|
||||||
|
QTranslator trans;
|
||||||
|
emit sendLanNumberSignals(0);
|
||||||
|
trans.load(":/Language/BatteryMonitor_ENG.qm");
|
||||||
|
QApplication::installTranslator(&trans);
|
||||||
|
m_MainWindow->ui->retranslateUi(m_MainWindow);
|
||||||
|
}
|
||||||
|
else if (language == "Chinese")
|
||||||
|
{
|
||||||
|
qDebug() << "ini lanuage index" << ini->value("System/Language");
|
||||||
|
ini->setValue("System/Language", 0);
|
||||||
|
ini->sync();
|
||||||
|
emit sendLanNumberSignals(1);
|
||||||
|
QTranslator trans;
|
||||||
|
trans.load(":/Language/BatteryMonitor_CHN.qm");
|
||||||
|
QApplication::installTranslator(&trans);
|
||||||
|
m_MainWindow->ui->retranslateUi(m_MainWindow);
|
||||||
|
}
|
||||||
|
|
||||||
|
emit sendBCUNumberSignals(BCUNumbers);
|
||||||
|
connect(this, &DialogLogin::sendBCUNumberSignals, m_MainWindow, &MainWindow::slot_getBcuNumberFromDialoglogin);
|
||||||
|
|
||||||
|
|
||||||
if(m_Serial->getAvailablePort().size() == 0) {
|
if(m_Serial->getAvailablePort().size() == 0) {
|
||||||
if(ini->value("System/Language") == MainWindow::LANGUAGE_ENG) {
|
if(ini->value("System/Language") == MainWindow::LANGUAGE_ENG) {
|
||||||
|
@ -246,7 +326,9 @@ void DialogLogin::slot_btnConnect_clicked()
|
||||||
m_MainWindow->statusBarConnectedIcon->setPixmap(QPixmap(QIcon(":/Image/connected2.png").pixmap(QSize(24, 24))));
|
m_MainWindow->statusBarConnectedIcon->setPixmap(QPixmap(QIcon(":/Image/connected2.png").pixmap(QSize(24, 24))));
|
||||||
m_MainWindow->show();
|
m_MainWindow->show();
|
||||||
// m_MainWindow->showMaximized();
|
// m_MainWindow->showMaximized();
|
||||||
|
// m_ModbusRTU->start();
|
||||||
|
m_ModbusRTU->start();
|
||||||
|
m_MainWindow->showMaximized();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(ini->value("System/Language") == MainWindow::LANGUAGE_ENG) {
|
if(ini->value("System/Language") == MainWindow::LANGUAGE_ENG) {
|
||||||
|
|
|
@ -31,10 +31,12 @@ private:
|
||||||
AppSerial *m_Serial;
|
AppSerial *m_Serial;
|
||||||
ModbusRTU *m_ModbusRTU;
|
ModbusRTU *m_ModbusRTU;
|
||||||
QSettings *ini;
|
QSettings *ini;
|
||||||
|
// QThread *thread;
|
||||||
int BCUNumbers;
|
int BCUNumbers;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void sendBCUNumberSignals(int number);
|
void sendBCUNumberSignals(int number);
|
||||||
|
void sendLanNumberSignals(int number);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void slot_comChangeStatus(QString name, bool flag);
|
void slot_comChangeStatus(QString name, bool flag);
|
||||||
|
|
613
dialoglogin.ui
613
dialoglogin.ui
|
@ -6,8 +6,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>260</width>
|
<width>362</width>
|
||||||
<height>320</height>
|
<height>444</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
@ -20,265 +20,388 @@
|
||||||
<string>Dialog</string>
|
<string>Dialog</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="0" column="0" colspan="2">
|
<item row="2" column="1">
|
||||||
<widget class="QGroupBox" name="groupBox">
|
<widget class="QGroupBox" name="groupBox">
|
||||||
<property name="title">
|
<property name="font">
|
||||||
<string>Communication</string>
|
<font>
|
||||||
|
<family>黑体</family>
|
||||||
|
<pointsize>11</pointsize>
|
||||||
|
</font>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_2">
|
<property name="title">
|
||||||
<item row="9" column="3">
|
<string/>
|
||||||
<widget class="QComboBox" name="comboBoxParity">
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
<item>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout" stretch="4,7,1,3,3">
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<widget class="QLabel" name="label_bluesunLogo">
|
||||||
<string>None</string>
|
<property name="sizePolicy">
|
||||||
</property>
|
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
<string>Odd</string>
|
<item row="0" column="0">
|
||||||
</property>
|
<widget class="QLabel" name="labelBCUQuantity_2">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<family>华文中宋</family>
|
||||||
|
<pointsize>10</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Language</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QComboBox" name="comboBoxLanguage">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<family>华文中宋</family>
|
||||||
|
<pointsize>10</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Chinese</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>English</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="labelSerialPort">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<family>华文中宋</family>
|
||||||
|
<pointsize>10</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Serial Port</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QComboBox" name="comboBoxSerialPort">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<family>华文中宋</family>
|
||||||
|
<pointsize>10</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QLabel" name="labelBaudRate">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<family>华文中宋</family>
|
||||||
|
<pointsize>10</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Baud Rate</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QComboBox" name="comboBoxBaudRate">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<family>华文中宋</family>
|
||||||
|
<pointsize>10</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>1200</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>2400</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>4800</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>9600</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>19200</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>38400</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>57600</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>115200</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="0">
|
||||||
|
<widget class="QLabel" name="labelDataBits">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<family>华文中宋</family>
|
||||||
|
<pointsize>10</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Data Bits</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="1">
|
||||||
|
<widget class="QComboBox" name="comboBoxDataBits">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<family>华文中宋</family>
|
||||||
|
<pointsize>10</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>5</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>6</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>7</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>8</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="0">
|
||||||
|
<widget class="QLabel" name="labelStopBits">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<family>华文中宋</family>
|
||||||
|
<pointsize>10</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Stop Bits</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="1">
|
||||||
|
<widget class="QComboBox" name="comboBoxStopBits">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<family>华文中宋</family>
|
||||||
|
<pointsize>10</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>1</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>2</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="5" column="0">
|
||||||
|
<widget class="QLabel" name="labelParity">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<family>华文中宋</family>
|
||||||
|
<pointsize>10</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Parity</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="5" column="1">
|
||||||
|
<widget class="QComboBox" name="comboBoxParity">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<family>华文中宋</family>
|
||||||
|
<pointsize>10</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>None</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Odd</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Even</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<spacer name="verticalSpacer">
|
||||||
<string>Even</string>
|
<property name="orientation">
|
||||||
</property>
|
<enum>Qt::Vertical</enum>
|
||||||
</item>
|
</property>
|
||||||
</widget>
|
<property name="sizeHint" stdset="0">
|
||||||
</item>
|
<size>
|
||||||
<item row="2" column="3">
|
<width>20</width>
|
||||||
<widget class="QComboBox" name="comboBoxSerialPort"/>
|
<height>40</height>
|
||||||
</item>
|
</size>
|
||||||
<item row="5" column="2">
|
</property>
|
||||||
<widget class="QLabel" name="labelBaudRate">
|
</spacer>
|
||||||
<property name="text">
|
|
||||||
<string>Baud Rate</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="5" column="3">
|
|
||||||
<widget class="QComboBox" name="comboBoxBaudRate">
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>1200</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,1,1">
|
||||||
<string>2400</string>
|
<item>
|
||||||
</property>
|
<spacer name="horizontalSpacer_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btnConnect">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<family>Microsoft YaHei UI</family>
|
||||||
|
<pointsize>12</pointsize>
|
||||||
|
<italic>false</italic>
|
||||||
|
<bold>true</bold>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="styleSheet">
|
||||||
|
<string notr="true">font: 700 12pt "Microsoft YaHei UI";</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Connect</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<widget class="QLabel" name="label_Copyright">
|
||||||
<string>4800</string>
|
<property name="sizePolicy">
|
||||||
</property>
|
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<family>幼圆</family>
|
||||||
|
<pointsize>12</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string><html><head/><body><p align="center">Copyright © 2016 Bluesun Solar Co.,Ltd </p><p align="center">All Rights Reserved.</p></body></html></string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
</layout>
|
||||||
<property name="text">
|
|
||||||
<string>9600</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>19200</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>38400</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>57600</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>115200</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="2">
|
|
||||||
<widget class="QLabel" name="labelSerialPort">
|
|
||||||
<property name="text">
|
|
||||||
<string>Serial Port</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="6" column="3">
|
|
||||||
<widget class="QComboBox" name="comboBoxDataBits">
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>5</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>6</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>7</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>8</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="8" column="2">
|
|
||||||
<widget class="QLabel" name="labelStopBits">
|
|
||||||
<property name="text">
|
|
||||||
<string>Stop Bits</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="9" column="2">
|
|
||||||
<widget class="QLabel" name="labelParity">
|
|
||||||
<property name="text">
|
|
||||||
<string>Parity</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="8" column="3">
|
|
||||||
<widget class="QComboBox" name="comboBoxStopBits">
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>1</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>2</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="6" column="2">
|
|
||||||
<widget class="QLabel" name="labelDataBits">
|
|
||||||
<property name="text">
|
|
||||||
<string>Data Bits</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="3">
|
|
||||||
<widget class="QComboBox" name="comboBoxBCUQuantity">
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>1</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>2</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>3</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>4</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>5</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>6</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>7</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>8</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>9</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>10</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>11</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>12</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>13</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>14</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>15</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>16</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="2">
|
|
||||||
<widget class="QLabel" name="labelBCUQuantity">
|
|
||||||
<property name="text">
|
|
||||||
<string>BCU Quantity</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0" colspan="2">
|
|
||||||
<spacer name="verticalSpacer">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Vertical</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>20</width>
|
|
||||||
<height>40</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="0" colspan="2">
|
|
||||||
<widget class="QPushButton" name="btnConnect">
|
|
||||||
<property name="text">
|
|
||||||
<string>Connect</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
|
|
@ -35,5 +35,7 @@
|
||||||
<file>Image/record-out-black.png</file>
|
<file>Image/record-out-black.png</file>
|
||||||
<file>Image/record-out-gray.png</file>
|
<file>Image/record-out-gray.png</file>
|
||||||
<file>Image/record-out-green.png</file>
|
<file>Image/record-out-green.png</file>
|
||||||
|
<file>Image/bluesun.png</file>
|
||||||
|
<file>Image/bunuo.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
15
main.cpp
15
main.cpp
|
@ -1,12 +1,27 @@
|
||||||
#include "dialoglogin.h"
|
#include "dialoglogin.h"
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QTranslator>
|
#include <QTranslator>
|
||||||
|
#include <QPersistentModelIndex>
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
// 设置高DPI
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||||
|
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||||
|
QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||||
|
QGuiApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||||
|
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
a.setStyleSheet("QToolTip { font-size: 18px; font-family: 'SimHei'; }");
|
a.setStyleSheet("QToolTip { font-size: 18px; font-family: 'SimHei'; }");
|
||||||
DialogLogin loginWidget;
|
DialogLogin loginWidget;
|
||||||
|
loginWidget.setStyleSheet("background-color: #FFFFFF;");
|
||||||
|
qRegisterMetaType<QList<QPersistentModelIndex>>("QList<QPersistentModelIndex>");
|
||||||
|
qRegisterMetaType<QAbstractItemModel::LayoutChangeHint>("QAbstractItemModel::LayoutChangeHint");
|
||||||
|
qRegisterMetaType<QVector<int>>("QVector<int>");
|
||||||
loginWidget.show();
|
loginWidget.show();
|
||||||
return a.exec();
|
return a.exec();
|
||||||
}
|
}
|
||||||
|
|
2291
mainwindow.cpp
2291
mainwindow.cpp
File diff suppressed because it is too large
Load Diff
70
mainwindow.h
70
mainwindow.h
|
@ -13,6 +13,7 @@ class QSettings;
|
||||||
class QLabel;
|
class QLabel;
|
||||||
class QFile;
|
class QFile;
|
||||||
class AppProto;
|
class AppProto;
|
||||||
|
class Appproto_English;
|
||||||
class ChartPaint;
|
class ChartPaint;
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
@ -34,14 +35,27 @@ public:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QStandardItemModel *model;
|
QStandardItemModel *model;
|
||||||
|
|
||||||
|
QStandardItemModel *modelBCU; //设置BCU目录
|
||||||
|
QStandardItem *rootItem;
|
||||||
|
|
||||||
|
QStandardItemModel *model_history_alarm;
|
||||||
|
QStandardItemModel *model_get_version;
|
||||||
|
|
||||||
ComLogin *m_ComLogin;
|
ComLogin *m_ComLogin;
|
||||||
AppProto *m_AppProto;
|
AppProto *m_AppProto;
|
||||||
|
Appproto_English *m_AppProto_English;
|
||||||
QSettings *ini;
|
QSettings *ini;
|
||||||
QFile *logFile;
|
QFile *logFile;
|
||||||
QLabel *statusBarConnectedIcon;
|
QLabel *statusBarConnectedIcon;
|
||||||
QLabel *statusBarConnectedType;
|
QLabel *statusBarConnectedType;
|
||||||
QLabel *statusBarCompany;
|
QLabel *statusBarCompany;
|
||||||
ChartPaint *chartPat;
|
QLabel *statusBarBcu;
|
||||||
|
QLabel *statusBarVersion;
|
||||||
|
// ChartPaint *chartPat;
|
||||||
|
QString currentBCU = "BCU01";
|
||||||
|
|
||||||
|
|
||||||
int BCUNumbers;
|
int BCUNumbers;
|
||||||
// QGridLayout *gridLayout;
|
// QGridLayout *gridLayout;
|
||||||
// QHBoxLayout *hBoxLayout;
|
// QHBoxLayout *hBoxLayout;
|
||||||
|
@ -58,9 +72,18 @@ public:
|
||||||
QList<int> base_info83_106;
|
QList<int> base_info83_106;
|
||||||
int battery_count;
|
int battery_count;
|
||||||
ModbusRTU *m_modbusrtu_main;
|
ModbusRTU *m_modbusrtu_main;
|
||||||
|
int lan;
|
||||||
|
|
||||||
int tabWidget_paraset_index = 0;
|
int tabWidget_paraset_index = 0;
|
||||||
|
|
||||||
|
QList<QLabel*> trouble_list;
|
||||||
|
QList<int> trouble_list_flag;
|
||||||
|
|
||||||
|
bool trouble_history = 1;
|
||||||
|
|
||||||
|
int count_history_alarm = 0; //如果不放到全局变量中去,每次刷新的都是同一个报警的内容,无法达到历史告警的作用
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum DataType{
|
enum DataType{
|
||||||
|
@ -94,6 +117,8 @@ private:
|
||||||
void init();
|
void init();
|
||||||
void setMenuStyle();
|
void setMenuStyle();
|
||||||
void pageBatteryInit();
|
void pageBatteryInit();
|
||||||
|
void pageHomeHistoryAlarm();
|
||||||
|
void pageFlashGetVersion();
|
||||||
void pageParaSetInit();
|
void pageParaSetInit();
|
||||||
void pageParaSetInit_alert_value();
|
void pageParaSetInit_alert_value();
|
||||||
void pageParaSetInit_alert_delay();
|
void pageParaSetInit_alert_delay();
|
||||||
|
@ -111,33 +136,62 @@ private:
|
||||||
int findMaxIndex(const QList<int> sgl_info);
|
int findMaxIndex(const QList<int> sgl_info);
|
||||||
int findMinIndex(const QList<int> sgl_info);
|
int findMinIndex(const QList<int> sgl_info);
|
||||||
|
|
||||||
|
void trubleListInit();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
// void setNum(QString value);
|
// void setNum(QString value);
|
||||||
|
void getLanNumberSlot(int number);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void showLogin();
|
void showLogin();
|
||||||
void closeLogin();
|
void closeLogin();
|
||||||
void write_regs_signals(int addr, const uint16_t data);
|
void write_regs_signals(int addr, const uint16_t data);
|
||||||
void read_regs_signals(int addr, int nb, uint16_t *data, int row);
|
void read_regs_signals(int addr, int nb, uint16_t *data, int row);
|
||||||
|
// void read_regs_input_signals_vol(int addr, int nb, uint16_t *data);
|
||||||
|
// void read_regs_input_signals_temp(int addr, int nb, uint16_t *data);
|
||||||
|
void row_of_bmus_index(int index);
|
||||||
|
void closeThread();
|
||||||
|
void openThread();
|
||||||
|
void quitThread();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void slot_getBcuNumberFromDialoglogin(int number);
|
void slot_getBcuNumberFromDialoglogin(int number);
|
||||||
void slot_pageDebugDisplayMessage(QByteArray byteArray, int dataType);
|
void slot_pageDebugDisplayMessage(QByteArray byteArray, int dataType, uint16_t *data);
|
||||||
void slot_pageHomeSglDataMessage(QByteArray byteArray, int dataType);
|
void slot_pageHomeSglDataMessage(QByteArray byteArray, int dataType, uint16_t *data);
|
||||||
void slot_pageHomeSglTempt(QByteArray byteArray, int dataType);
|
void slot_pageHomeSglTempt(QByteArray byteArray, int dataType, uint16_t *data);
|
||||||
void slot_pageHomeBaseInfo1_45(QByteArray byteArray, int dataType);
|
void slot_pageHomeBaseInfo1_45(QByteArray byteArray, int dataType, uint16_t *data);
|
||||||
void slot_pageHomeBaseInfo57_78(QByteArray byteArray, int dataType);
|
void slot_pageHomeBaseInfo57_78(QByteArray byteArray, int dataType, uint16_t *data);
|
||||||
void slot_pageHomeBaseInfo83_106(QByteArray byteArray, int dataType);
|
void slot_pageHomeBaseInfo83_106(QByteArray byteArray, int dataType, uint16_t *data);
|
||||||
void slot_pageHomeBaseInfo47_49_51_53_55(QList<int> byteArray, int dataType);
|
void slot_pageHomeBaseInfo47_49_51_53_55(QList<int> byteArray, int dataType);
|
||||||
void slot_pageParaSetShow(QByteArray byteArray, int dataType, int row, int nb);
|
void slot_pageParaSetShow(int row, int nb, uint16_t *data);
|
||||||
|
void slot_testData(uint16_t *data);
|
||||||
|
void slot_pageHomeFault(QByteArray byteArray, int dataType, uint16_t *data);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void closeEvent(QCloseEvent *e) override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_pageParaSetCheck_stateChanged(int arg1);
|
void on_pageParaSetCheck_stateChanged(int arg1);
|
||||||
void on_pageParaSetRead_clicked();
|
void on_pageParaSetRead_clicked();
|
||||||
void on_pageParaSetWrite_clicked();
|
void on_pageParaSetWrite_clicked();
|
||||||
void on_tabChanged(int index);
|
void on_tabChanged(int index);
|
||||||
|
void on_comBoxBCUSelect(int index);
|
||||||
// void on_horizontalSlider_valueChanged(int value);
|
// void on_horizontalSlider_valueChanged(int value);
|
||||||
|
|
||||||
|
void on_btn_close_pos_clicked();
|
||||||
|
|
||||||
|
void on_btn_open_pos_clicked();
|
||||||
|
|
||||||
|
void on_btn_close_neg_clicked();
|
||||||
|
|
||||||
|
void on_btn_open_neg_clicked();
|
||||||
|
|
||||||
|
void on_btn_close_prechg_clicked();
|
||||||
|
|
||||||
|
void on_btn_open_prechg_clicked();
|
||||||
|
|
||||||
|
void on_btnImport_clicked();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct Battery_data {
|
struct Battery_data {
|
||||||
uint16_t pack_total_voltage; // 电池组总压
|
uint16_t pack_total_voltage; // 电池组总压
|
||||||
|
|
18632
mainwindow.ui
18632
mainwindow.ui
File diff suppressed because it is too large
Load Diff
213
modbusrtu.cpp
213
modbusrtu.cpp
|
@ -3,10 +3,13 @@
|
||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include "modbus-private.h"
|
#include "modbus-private.h"
|
||||||
|
#include <QMessageBox>
|
||||||
ModbusRTU::ModbusRTU(QObject *parent) : QObject(parent)
|
#include <QEventLoop>
|
||||||
|
ModbusRTU::ModbusRTU(QObject *parent) : QThread(parent)
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
|
// start();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ModbusRTU::~ModbusRTU()
|
ModbusRTU::~ModbusRTU()
|
||||||
|
@ -17,31 +20,19 @@ ModbusRTU::~ModbusRTU()
|
||||||
|
|
||||||
void ModbusRTU::init()
|
void ModbusRTU::init()
|
||||||
{
|
{
|
||||||
timer50msId = startTimer(50);
|
|
||||||
timer100msId = startTimer(100);
|
|
||||||
timer200msId = startTimer(200);
|
|
||||||
timer1000msId = startTimer(1000);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModbusRTU::timerEvent(QTimerEvent *event)
|
void ModbusRTU::run()
|
||||||
{
|
{
|
||||||
if(isConnect != true) {
|
qDebug() << "进入线程:" << QThread::currentThread();
|
||||||
return;
|
while(true)
|
||||||
}
|
{
|
||||||
else {
|
if (closeThread)
|
||||||
if(event->timerId() == timer50msId) {
|
{
|
||||||
|
QElapsedTimer time;
|
||||||
}
|
time.start();
|
||||||
if(event->timerId() == timer100msId) {
|
QThread::msleep(300);
|
||||||
|
|
||||||
}
|
|
||||||
if(event->timerId() == timer200msId) {
|
|
||||||
|
|
||||||
}
|
|
||||||
if(event->timerId() == timer1000msId) {
|
|
||||||
uint16_t sgl_vol[112]; // Buffer to store the registers
|
|
||||||
uint16_t sgl_tempt[112];
|
|
||||||
uint16_t base1_45[45];
|
uint16_t base1_45[45];
|
||||||
uint16_t base57_78[22];
|
uint16_t base57_78[22];
|
||||||
uint16_t base83_106[24];
|
uint16_t base83_106[24];
|
||||||
|
@ -50,22 +41,24 @@ void ModbusRTU::timerEvent(QTimerEvent *event)
|
||||||
uint16_t base51[1];
|
uint16_t base51[1];
|
||||||
uint16_t base53[1];
|
uint16_t base53[1];
|
||||||
uint16_t base55[1];
|
uint16_t base55[1];
|
||||||
uint16_t base47_49_51_53_55[5];
|
|
||||||
uint16_t test2[2] = {10, 20};
|
|
||||||
QList<int> base_list_47_49_51_53_55;
|
QList<int> base_list_47_49_51_53_55;
|
||||||
int ret_base1_45 = modbus_read_input_registers(m_ModbusRTUDevice, 1, 45, base1_45);
|
uint16_t sgl_vol[16]; // Buffer to store the registers
|
||||||
if(MODBUS_ERR == ret_base1_45) {
|
uint16_t sgl_tempt[16];
|
||||||
// qDebug() << "modbus no message";
|
uint16_t fault[8];
|
||||||
return;
|
|
||||||
|
label: int ret_base1_45 = modbus_read_input_registers(m_ModbusRTUDevice, 1, 45, base1_45);
|
||||||
|
if(MODBUS_ERR == ret_base1_45)
|
||||||
|
{
|
||||||
|
goto label;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
QByteArray sendArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->sendMsg), m_ModbusRTUDevice->sendMsgLen);
|
QByteArray sendArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->sendMsg), m_ModbusRTUDevice->sendMsgLen);
|
||||||
emit sig_showModbusData_base_info1_45(sendArray, TypeSendData);
|
emit sig_showModbusData_base_info1_45(sendArray, TypeSendData, base1_45);
|
||||||
free(m_ModbusRTUDevice->sendMsg);
|
free(m_ModbusRTUDevice->sendMsg);
|
||||||
QByteArray recvArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->recvMsg), m_ModbusRTUDevice->recvMsgLen);
|
QByteArray recvArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->recvMsg), m_ModbusRTUDevice->recvMsgLen);
|
||||||
emit sig_showModbusData_base_info1_45(recvArray, TypeRecvData);
|
emit sig_showModbusData_base_info1_45(recvArray, TypeRecvData, base1_45);
|
||||||
free(m_ModbusRTUDevice->recvMsg);
|
free(m_ModbusRTUDevice->recvMsg);
|
||||||
// qDebug() << "in modbus:" << base1_45;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ret_base47 = modbus_read_input_registers(m_ModbusRTUDevice, 47, 1, base47);
|
int ret_base47 = modbus_read_input_registers(m_ModbusRTUDevice, 47, 1, base47);
|
||||||
|
@ -82,7 +75,6 @@ void ModbusRTU::timerEvent(QTimerEvent *event)
|
||||||
QByteArray sendArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->sendMsg), m_ModbusRTUDevice->sendMsgLen);
|
QByteArray sendArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->sendMsg), m_ModbusRTUDevice->sendMsgLen);
|
||||||
emit sig_showModbusData_base_info47_49_51_53_55(sendArray, TypeSendData);
|
emit sig_showModbusData_base_info47_49_51_53_55(sendArray, TypeSendData);
|
||||||
free(m_ModbusRTUDevice->sendMsg);
|
free(m_ModbusRTUDevice->sendMsg);
|
||||||
// QByteArray recvArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->recvMsg), m_ModbusRTUDevice->recvMsgLen);
|
|
||||||
QByteArray recvArray;
|
QByteArray recvArray;
|
||||||
recvArray.append(reinterpret_cast<char*>(&base47), sizeof(base47));
|
recvArray.append(reinterpret_cast<char*>(&base47), sizeof(base47));
|
||||||
recvArray.append(reinterpret_cast<char*>(&base49), sizeof(base49));
|
recvArray.append(reinterpret_cast<char*>(&base49), sizeof(base49));
|
||||||
|
@ -94,97 +86,158 @@ void ModbusRTU::timerEvent(QTimerEvent *event)
|
||||||
uint16_t value;
|
uint16_t value;
|
||||||
memcpy(&value, recvArray.data() + i, 2);
|
memcpy(&value, recvArray.data() + i, 2);
|
||||||
base_list_47_49_51_53_55.append(value);
|
base_list_47_49_51_53_55.append(value);
|
||||||
// base47_49_51_53_55[i] = value;
|
|
||||||
// qDebug() << "Value: " << value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
emit sig_showModbusData_base_info_list_47_49_51_53_55(base_list_47_49_51_53_55, TypeRecvData);
|
emit sig_showModbusData_base_info_list_47_49_51_53_55(base_list_47_49_51_53_55, TypeRecvData);
|
||||||
// emit sig_showModbusData_base_info47_49_51_53_55(sendArray, TypeSendData);
|
|
||||||
free(m_ModbusRTUDevice->recvMsg);
|
free(m_ModbusRTUDevice->recvMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ret_base57_78 = modbus_read_input_registers(m_ModbusRTUDevice, 57, 22, base57_78);
|
int ret_base57_78 = modbus_read_input_registers(m_ModbusRTUDevice, 57, 22, base57_78);
|
||||||
if(MODBUS_ERR == ret_base57_78) {
|
if(MODBUS_ERR == ret_base57_78)
|
||||||
// qDebug() << "modbus no message";
|
{
|
||||||
return;
|
goto label;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
QByteArray sendArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->sendMsg), m_ModbusRTUDevice->sendMsgLen);
|
QByteArray sendArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->sendMsg), m_ModbusRTUDevice->sendMsgLen);
|
||||||
emit sig_showModbusData_base_info57_78(sendArray, TypeSendData);
|
emit sig_showModbusData_base_info57_78(sendArray, TypeSendData, base57_78);
|
||||||
free(m_ModbusRTUDevice->sendMsg);
|
free(m_ModbusRTUDevice->sendMsg);
|
||||||
QByteArray recvArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->recvMsg), m_ModbusRTUDevice->recvMsgLen);
|
QByteArray recvArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->recvMsg), m_ModbusRTUDevice->recvMsgLen);
|
||||||
emit sig_showModbusData_base_info57_78(recvArray, TypeRecvData);
|
emit sig_showModbusData_base_info57_78(recvArray, TypeRecvData, base57_78);
|
||||||
|
free(m_ModbusRTUDevice->recvMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ret_fault = modbus_read_input_registers(m_ModbusRTUDevice, 66, 8, fault);
|
||||||
|
if(MODBUS_ERR == ret_fault)
|
||||||
|
{
|
||||||
|
goto label;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QByteArray sendArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->sendMsg), m_ModbusRTUDevice->sendMsgLen);
|
||||||
|
emit sig_showFault(sendArray, TypeSendData, fault);
|
||||||
|
free(m_ModbusRTUDevice->sendMsg);
|
||||||
|
QByteArray recvArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->recvMsg), m_ModbusRTUDevice->recvMsgLen);
|
||||||
|
emit sig_showFault(recvArray, TypeRecvData,fault);
|
||||||
free(m_ModbusRTUDevice->recvMsg);
|
free(m_ModbusRTUDevice->recvMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ret_base83_106 = modbus_read_input_registers(m_ModbusRTUDevice, 83, 24, base83_106);
|
int ret_base83_106 = modbus_read_input_registers(m_ModbusRTUDevice, 83, 24, base83_106);
|
||||||
if(MODBUS_ERR == ret_base83_106) {
|
if(MODBUS_ERR == ret_base83_106)
|
||||||
// qDebug() << "modbus no message";
|
{
|
||||||
return;
|
goto label;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
QByteArray sendArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->sendMsg), m_ModbusRTUDevice->sendMsgLen);
|
QByteArray sendArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->sendMsg), m_ModbusRTUDevice->sendMsgLen);
|
||||||
emit sig_showModbusData_base_info83_106(sendArray, TypeSendData);
|
emit sig_showModbusData_base_info83_106(sendArray, TypeSendData, base83_106);
|
||||||
free(m_ModbusRTUDevice->sendMsg);
|
free(m_ModbusRTUDevice->sendMsg);
|
||||||
QByteArray recvArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->recvMsg), m_ModbusRTUDevice->recvMsgLen);
|
QByteArray recvArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->recvMsg), m_ModbusRTUDevice->recvMsgLen);
|
||||||
emit sig_showModbusData_base_info83_106(recvArray, TypeRecvData);
|
emit sig_showModbusData_base_info83_106(recvArray, TypeRecvData, base83_106);
|
||||||
|
free(m_ModbusRTUDevice->recvMsg);
|
||||||
|
}
|
||||||
|
int volAddress = (1001 + BMUIndex * 16);
|
||||||
|
int tempAddress = (1601 + BMUIndex * 16);
|
||||||
|
|
||||||
|
int ret_vol = modbus_read_input_registers(m_ModbusRTUDevice, volAddress, 16, sgl_vol);
|
||||||
|
if(MODBUS_ERR == ret_vol)
|
||||||
|
{
|
||||||
|
goto label;
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QByteArray sendArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->sendMsg), m_ModbusRTUDevice->sendMsgLen);
|
||||||
|
emit sig_showModbusData(sendArray, TypeSendData, sgl_vol);
|
||||||
|
free(m_ModbusRTUDevice->sendMsg);
|
||||||
|
QByteArray recvArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->recvMsg), m_ModbusRTUDevice->recvMsgLen);
|
||||||
|
emit sig_showModbusData(recvArray, TypeRecvData, sgl_vol);
|
||||||
|
free(m_ModbusRTUDevice->recvMsg);
|
||||||
|
}
|
||||||
|
int ret_tempt = modbus_read_input_registers(m_ModbusRTUDevice, tempAddress, 16, sgl_tempt);
|
||||||
|
if(MODBUS_ERR == ret_tempt)
|
||||||
|
{
|
||||||
|
goto label;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QByteArray sendArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->sendMsg), m_ModbusRTUDevice->sendMsgLen);
|
||||||
|
emit sig_showModbusData_sgl_tempt(sendArray, TypeSendData, sgl_tempt);
|
||||||
|
free(m_ModbusRTUDevice->sendMsg);
|
||||||
|
QByteArray recvArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->recvMsg), m_ModbusRTUDevice->recvMsgLen);
|
||||||
|
emit sig_showModbusData_sgl_tempt(recvArray, TypeRecvData, sgl_tempt);
|
||||||
free(m_ModbusRTUDevice->recvMsg);
|
free(m_ModbusRTUDevice->recvMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ret_vol = modbus_read_input_registers(m_ModbusRTUDevice, 1001, 112, sgl_vol);
|
int milsec = time.elapsed();
|
||||||
if(MODBUS_ERR == ret_vol) {
|
qDebug() <<"the time: " << milsec;
|
||||||
// qDebug() << "modbus no message";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
QByteArray sendArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->sendMsg), m_ModbusRTUDevice->sendMsgLen);
|
|
||||||
emit sig_showModbusData(sendArray, TypeSendData);
|
|
||||||
free(m_ModbusRTUDevice->sendMsg);
|
|
||||||
QByteArray recvArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->recvMsg), m_ModbusRTUDevice->recvMsgLen);
|
|
||||||
emit sig_showModbusData(recvArray, TypeRecvData);
|
|
||||||
free(m_ModbusRTUDevice->recvMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ret_tempt = modbus_read_input_registers(m_ModbusRTUDevice, 1601, 112, sgl_tempt);
|
|
||||||
if(MODBUS_ERR == ret_tempt) {
|
|
||||||
// qDebug() << "modbus no message";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
QByteArray sendArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->sendMsg), m_ModbusRTUDevice->sendMsgLen);
|
|
||||||
emit sig_showModbusData_sgl_tempt(sendArray, TypeSendData);
|
|
||||||
free(m_ModbusRTUDevice->sendMsg);
|
|
||||||
QByteArray recvArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->recvMsg), m_ModbusRTUDevice->recvMsgLen);
|
|
||||||
emit sig_showModbusData_sgl_tempt(recvArray, TypeRecvData);
|
|
||||||
free(m_ModbusRTUDevice->recvMsg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ModbusRTU::write_regs_slot(int addr,const uint16_t data)
|
void ModbusRTU::write_regs_slot(int addr,const uint16_t data)
|
||||||
{
|
{
|
||||||
|
// qDebug() << "write:进入线程:" << QThread::currentThread();
|
||||||
int rc = write_single_register(addr, data);
|
int rc = write_single_register(addr, data);
|
||||||
|
this->blockSignals(true);
|
||||||
if(MODBUS_ERR == rc) {
|
if(MODBUS_ERR == rc) {
|
||||||
qDebug() << "######modbus no message";
|
qDebug() << "write######modbus no message" << modbus_strerror(errno);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModbusRTU::read_regs_slot(int addr, int nb, uint16_t *data, int row)
|
void ModbusRTU::read_regs_slot(int addr, int nb, uint16_t *data, int row)
|
||||||
{
|
{
|
||||||
|
// qDebug() << "read:进入线程:" << QThread::currentThread();
|
||||||
|
// uint16_t temp[10];
|
||||||
|
// uint16_t temp1[10] = {1, 2, 3, 4, 5};
|
||||||
|
// memset(temp1, 0, sizeof(temp));
|
||||||
|
qDebug() << "current add and nb" << addr << " " << nb;
|
||||||
int rc = read_holding_register(addr, nb, data);
|
int rc = read_holding_register(addr, nb, data);
|
||||||
if(MODBUS_ERR == rc) {
|
if(MODBUS_ERR == rc) {
|
||||||
// qDebug() << "modbus no message";
|
qDebug() << "read modbus no message" << modbus_strerror(errno);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
|
// qDebug() << "read rc" << rc;
|
||||||
|
// QByteArray sendArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->sendMsg), m_ModbusRTUDevice->sendMsgLen);
|
||||||
|
// emit sig_showReadHoldingRegs(row, nb, temp);
|
||||||
|
// free(m_ModbusRTUDevice->sendMsg);
|
||||||
QByteArray recvArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->recvMsg), m_ModbusRTUDevice->recvMsgLen);
|
QByteArray recvArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->recvMsg), m_ModbusRTUDevice->recvMsgLen);
|
||||||
emit sig_showReadHoldingRegs(recvArray, TypeRecvData, row, nb);
|
emit sig_showReadHoldingRegs(row, nb, data);
|
||||||
free(m_ModbusRTUDevice->recvMsg);
|
free(m_ModbusRTUDevice->recvMsg);
|
||||||
|
// emit sig_testData(temp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ModbusRTU::slot_pauseThread()
|
||||||
|
{
|
||||||
|
qDebug() << "暂停线程";
|
||||||
|
closeThread = false;
|
||||||
|
// emit paused();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModbusRTU::slot_resumeThread()
|
||||||
|
{
|
||||||
|
qDebug() << "恢复线程";
|
||||||
|
|
||||||
|
// eventLoop.exit();
|
||||||
|
// eventLoop.quit();
|
||||||
|
|
||||||
|
// qDebug() << "Event loop state before quit: " << eventLoop.isRunning();
|
||||||
|
closeThread = true;
|
||||||
|
// emit resumed();
|
||||||
|
// qDebug() << "closeThread:" << closeThread;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModbusRTU::change_BMUIndex_slot(int index)
|
||||||
|
{
|
||||||
|
BMUIndex = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ModbusRTU::modbusRTUConnect(const char *comPort, int baudRate, char parity, int dataBit, int stopBit)
|
bool ModbusRTU::modbusRTUConnect(const char *comPort, int baudRate, char parity, int dataBit, int stopBit)
|
||||||
{
|
{
|
||||||
qDebug() << "comPort:" << comPort << "baudRate:" << baudRate << "parity:" << parity << "dataBit" << dataBit << "stopBit:" << stopBit;
|
qDebug() << "comPort:" << comPort << "baudRate:" << baudRate << "parity:" << parity << "dataBit" << dataBit << "stopBit:" << stopBit;
|
||||||
|
|
41
modbusrtu.h
41
modbusrtu.h
|
@ -3,18 +3,24 @@
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include "modbus.h"
|
#include "modbus.h"
|
||||||
|
#include <QThread>
|
||||||
|
#include <QEventLoop>
|
||||||
|
|
||||||
class QTimer;
|
class QTimer;
|
||||||
|
|
||||||
class ModbusRTU : public QObject
|
class ModbusRTU : public QThread
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
ModbusRTU(QObject *parent = nullptr);
|
ModbusRTU(QObject *parent = nullptr);
|
||||||
~ModbusRTU();
|
~ModbusRTU();
|
||||||
void timerEvent(QTimerEvent *event);
|
|
||||||
|
public slots:
|
||||||
void write_regs_slot(int addr, const uint16_t data);
|
void write_regs_slot(int addr, const uint16_t data);
|
||||||
void read_regs_slot(int addr, int nb, uint16_t *data, int row);
|
void read_regs_slot(int addr, int nb, uint16_t *data, int row);
|
||||||
|
// void read_regs_input_slot_vol(int addr, int nb, uint16_t *data);
|
||||||
|
// void read_regs_input_slot_temp(int addr, int nb, uint16_t *data);
|
||||||
|
void change_BMUIndex_slot(int index);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
modbus_t *m_ModbusRTUDevice;
|
modbus_t *m_ModbusRTUDevice;
|
||||||
|
@ -24,14 +30,16 @@ public:
|
||||||
char parity;
|
char parity;
|
||||||
int dataBit;
|
int dataBit;
|
||||||
int stopBit;
|
int stopBit;
|
||||||
|
int BMUIndex = 0;
|
||||||
|
bool closeThread = true;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void run() override;
|
||||||
|
QEventLoop eventLoop;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int timer50msId;
|
|
||||||
int timer100msId;
|
|
||||||
int timer200msId;
|
|
||||||
int timer1000msId;
|
|
||||||
|
|
||||||
static constexpr int MODBUS_ERR = -1;
|
static constexpr int MODBUS_ERR = -1;
|
||||||
|
|
||||||
enum DataType{
|
enum DataType{
|
||||||
TypeRecvData,
|
TypeRecvData,
|
||||||
|
@ -62,17 +70,22 @@ public:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void sig_ModbusRTUConnected();
|
void sig_ModbusRTUConnected();
|
||||||
void sig_showModbusData(QByteArray byteArray, int dataType);
|
void sig_showModbusData(QByteArray byteArray, int dataType, uint16_t *data);
|
||||||
void sig_showModbusData_sgl_tempt(QByteArray byteArray, int dataType);
|
void sig_showModbusData_sgl_tempt(QByteArray byteArray, int dataType, uint16_t *data);
|
||||||
void sig_showModbusData_base_info1_45(QByteArray byteArray,int dataType);
|
void sig_showModbusData_base_info1_45(QByteArray byteArray,int dataType, uint16_t *data);
|
||||||
void sig_showModbusData_base_info57_78(QByteArray byteArray,int dataType);
|
void sig_showModbusData_base_info57_78(QByteArray byteArray,int dataType, uint16_t *data);
|
||||||
void sig_showModbusData_base_info83_106(QByteArray byteArray,int dataType);
|
void sig_showModbusData_base_info83_106(QByteArray byteArray,int dataType, uint16_t *data);
|
||||||
void sig_showModbusData_base_info47_49_51_53_55(QByteArray byteArray,int dataType);
|
void sig_showModbusData_base_info47_49_51_53_55(QByteArray byteArray,int dataType);
|
||||||
void sig_showModbusData_base_info_list_47_49_51_53_55(QList<int> byteArray,int dataType);
|
void sig_showModbusData_base_info_list_47_49_51_53_55(QList<int> byteArray,int dataType);
|
||||||
void sig_showReadHoldingRegs(QByteArray byteArray,int dataType, int row, int nb);
|
void sig_showReadHoldingRegs(int row, int nb, uint16_t *data);
|
||||||
|
void sig_showFault(QByteArray byteArray, int dataType, uint16_t *data);
|
||||||
|
void paused();
|
||||||
|
void resumed();
|
||||||
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void slot_pauseThread();
|
||||||
|
void slot_resumeThread();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MODBUSRTU_H
|
#endif // MODBUSRTU_H
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
@echo off
|
||||||
|
|
||||||
|
set local
|
||||||
|
:: 设置库路径
|
||||||
|
SET LIB_PATH=..\library\libprotobuf\lib
|
||||||
|
:: 设置环境变量
|
||||||
|
SET PATH=%LIB_PATH%;%PATH%
|
||||||
|
:: 设置protoc路径
|
||||||
|
SET PROTOC_PATH=..\library\libprotobuf\bin\protoc.exe
|
||||||
|
:: 编译proto文件
|
||||||
|
%PROTOC_PATH% --cpp_out=.\ *.proto
|
||||||
|
|
||||||
|
pause
|
||||||
|
endlocal
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,105 @@
|
||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package BatteryConfig_English;
|
||||||
|
|
||||||
|
message Item{
|
||||||
|
repeated Attributes ItemAttr = 1;
|
||||||
|
repeated Attributes_balance ItemAttr_balance = 2;
|
||||||
|
repeated Attributes_DIDO ItemAttr_DIDO = 3;
|
||||||
|
repeated Attributes_SOX ItemAttr_SOX = 4;
|
||||||
|
repeated Attributes_other ItemAttr_other = 5;
|
||||||
|
repeated Attributes_alert_value ItemAttr_alert_value = 6;
|
||||||
|
repeated Attributes_alert_delay ItemAttr_alert_delay = 7;
|
||||||
|
repeated Attributes_alert_release_value ItemAttr_alert_release_value = 8;
|
||||||
|
repeated Attributes_alert_release_delay ItemAttr_alert_release_delay = 9;
|
||||||
|
repeated Attributes_alert_dropcurr_rate ItemAttr_alert_dropcurr_rate = 10;
|
||||||
|
repeated Attributes_alert_solve_measure ItemAttr_alert_solve_measure = 11;
|
||||||
|
}
|
||||||
|
|
||||||
|
message Attributes{
|
||||||
|
string name = 1;
|
||||||
|
int32 addr = 2;
|
||||||
|
int32 value = 3;
|
||||||
|
float scale = 4;
|
||||||
|
string introduce = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
message Attributes_balance{
|
||||||
|
string name = 1;
|
||||||
|
int32 addr = 2;
|
||||||
|
int32 value = 3;
|
||||||
|
float scale = 4;
|
||||||
|
string introduce = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
message Attributes_DIDO{
|
||||||
|
string name = 1;
|
||||||
|
int32 addr = 2;
|
||||||
|
int32 value = 3;
|
||||||
|
float scale = 4;
|
||||||
|
string introduce = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
message Attributes_SOX{
|
||||||
|
string name = 1;
|
||||||
|
int32 addr = 2;
|
||||||
|
int32 value = 3;
|
||||||
|
float scale = 4;
|
||||||
|
string introduce = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
message Attributes_other{
|
||||||
|
string name = 1;
|
||||||
|
int32 addr = 2;
|
||||||
|
int32 value = 3;
|
||||||
|
float scale = 4;
|
||||||
|
string introduce = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
message Attributes_alert_value{
|
||||||
|
string name = 1;
|
||||||
|
int32 addr = 2;
|
||||||
|
int32 value = 3;
|
||||||
|
float scale = 4;
|
||||||
|
string introduce = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
message Attributes_alert_delay{
|
||||||
|
string name = 1;
|
||||||
|
int32 addr = 2;
|
||||||
|
int32 value = 3;
|
||||||
|
float scale = 4;
|
||||||
|
string introduce = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
message Attributes_alert_release_value{
|
||||||
|
string name = 1;
|
||||||
|
int32 addr = 2;
|
||||||
|
int32 value = 3;
|
||||||
|
float scale = 4;
|
||||||
|
string introduce = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
message Attributes_alert_release_delay{
|
||||||
|
string name = 1;
|
||||||
|
int32 addr = 2;
|
||||||
|
int32 value = 3;
|
||||||
|
float scale = 4;
|
||||||
|
string introduce = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
message Attributes_alert_dropcurr_rate{
|
||||||
|
string name = 1;
|
||||||
|
int32 addr = 2;
|
||||||
|
int32 value = 3;
|
||||||
|
float scale = 4;
|
||||||
|
string introduce = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
message Attributes_alert_solve_measure{
|
||||||
|
string name = 1;
|
||||||
|
int32 addr = 2;
|
||||||
|
int32 value = 3;
|
||||||
|
float scale = 4;
|
||||||
|
string introduce = 5;
|
||||||
|
}
|
|
@ -0,0 +1,160 @@
|
||||||
|
#include "upgradeicon.h"
|
||||||
|
|
||||||
|
upgradeIcon::upgradeIcon(QWidget *parent) : QWidget(parent)
|
||||||
|
{
|
||||||
|
setContentsMargins(0,0,0,0);
|
||||||
|
borderWidth = 4;
|
||||||
|
headWidth = 20;
|
||||||
|
value = 50;
|
||||||
|
minValue = 0;
|
||||||
|
maxValue = 100;
|
||||||
|
alarmValue = 20;
|
||||||
|
borderRadio = 10;
|
||||||
|
drawInRadio = 8;
|
||||||
|
borderColor = QColor(96, 96, 96);
|
||||||
|
}
|
||||||
|
|
||||||
|
void upgradeIcon::paintEvent(QPaintEvent *)
|
||||||
|
{
|
||||||
|
QPainter painter(this);
|
||||||
|
painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
|
||||||
|
drawBorder(&painter);
|
||||||
|
// drawRightHead(&painter);
|
||||||
|
drawBackground(&painter);
|
||||||
|
drawText(&painter);
|
||||||
|
}
|
||||||
|
|
||||||
|
void upgradeIcon::resizeEvent(QResizeEvent *)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// 画边框
|
||||||
|
void upgradeIcon::drawBorder(QPainter *painter)
|
||||||
|
{
|
||||||
|
painter->save();
|
||||||
|
painter->setPen(QPen(borderColor,borderWidth));
|
||||||
|
borderRect = QRect(borderWidth,borderWidth,width()-2*borderWidth-headWidth,height()-2*borderWidth);
|
||||||
|
painter->drawRoundedRect(borderRect,borderRadio,borderRadio);
|
||||||
|
painter->restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 画右边电池头部
|
||||||
|
void upgradeIcon::drawRightHead(QPainter *painter)
|
||||||
|
{
|
||||||
|
painter->save();
|
||||||
|
double headHeight = height()/2;
|
||||||
|
painter->setPen(Qt::NoPen);
|
||||||
|
painter->setBrush(QColor(96, 96, 96));
|
||||||
|
QRectF headRect = QRectF(width()-headWidth-borderWidth/2,height()/2-headHeight/2,headWidth / 1.75,headHeight);
|
||||||
|
painter->drawRect(headRect);
|
||||||
|
painter->restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 画数值对应颜色
|
||||||
|
void upgradeIcon::drawBackground(QPainter *painter)
|
||||||
|
{
|
||||||
|
painter->save();
|
||||||
|
double batteryWidth = width()-headWidth-3*borderWidth; // 电池宽度
|
||||||
|
double bgWidth= value * batteryWidth / (maxValue-minValue); // 背景绘制宽度
|
||||||
|
QLinearGradient batteryGradient(QPointF(0, 0), QPointF(borderWidth+bgWidth,height()));
|
||||||
|
|
||||||
|
batteryGradient.setColorAt(0.0, QColor(135, 206, 250));
|
||||||
|
// batteryGradient.setColorAt(1.0, QColor(102, 255, 0));
|
||||||
|
|
||||||
|
painter->setBrush(QBrush(batteryGradient));
|
||||||
|
painter->setPen(Qt::NoPen);
|
||||||
|
QRectF rectBg = QRectF(borderWidth+borderWidth/2,borderWidth+borderWidth/2,bgWidth,height()-3*borderWidth);
|
||||||
|
painter->drawRoundedRect(rectBg,drawInRadio,drawInRadio);
|
||||||
|
painter->restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 画百分比数值
|
||||||
|
void upgradeIcon::drawText(QPainter *painter)
|
||||||
|
{
|
||||||
|
painter->save();
|
||||||
|
QString value_str = QString("%1%").arg(value);
|
||||||
|
painter->setPen(QPen(QColor(Qt::black)));
|
||||||
|
double w = qMin(borderRect.width(),borderRect.height());
|
||||||
|
// 文字大小自适应 90为控件初始高度,30位字体默认大小
|
||||||
|
int fontSize = 30 * w / 90;
|
||||||
|
painter->setFont(QFont("Microsoft YaHei UI",fontSize));
|
||||||
|
painter->drawText(borderRect,value_str,QTextOption(Qt::AlignHCenter | Qt::AlignVCenter));
|
||||||
|
painter->restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置当前值
|
||||||
|
void upgradeIcon::setValue(int value)
|
||||||
|
{
|
||||||
|
this->value = value;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void upgradeIcon::setMinValue(int min)
|
||||||
|
{
|
||||||
|
minValue = min;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void upgradeIcon::setMaxValue(int max)
|
||||||
|
{
|
||||||
|
maxValue = max;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void upgradeIcon::setRange(int min, int max)
|
||||||
|
{
|
||||||
|
minValue = min;
|
||||||
|
maxValue = max;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void upgradeIcon::setBorderWidth(int width)
|
||||||
|
{
|
||||||
|
borderWidth = width;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void upgradeIcon::setBorderRadio(int radio)
|
||||||
|
{
|
||||||
|
borderRadio = radio;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void upgradeIcon::setInRadio(int radio)
|
||||||
|
{
|
||||||
|
drawInRadio = radio;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void upgradeIcon::setAlarmValue(int alarm)
|
||||||
|
{
|
||||||
|
alarmValue = alarm;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void upgradeIcon::setBorderColor(QColor color)
|
||||||
|
{
|
||||||
|
borderColor = color;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
int upgradeIcon::getValue()
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
int upgradeIcon::getMinValue()
|
||||||
|
{
|
||||||
|
return minValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int upgradeIcon::getMaxValue()
|
||||||
|
{
|
||||||
|
return maxValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int upgradeIcon::getAlarmValue()
|
||||||
|
{
|
||||||
|
return alarmValue;
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
#ifndef UPGRADEICON_H
|
||||||
|
#define UPGRADEICON_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QtMath>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
class upgradeIcon : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(int value READ getValue WRITE setValue)
|
||||||
|
Q_PROPERTY(int minValue READ getMinValue WRITE setMinValue)
|
||||||
|
Q_PROPERTY(int maxValue READ getMaxValue WRITE setMaxValue)
|
||||||
|
Q_PROPERTY(int alarmValue READ getAlarmValue WRITE setAlarmValue)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit upgradeIcon(QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void paintEvent(QPaintEvent *) override;
|
||||||
|
void resizeEvent(QResizeEvent *) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void drawBorder(QPainter *painter);
|
||||||
|
void drawRightHead(QPainter *painter);
|
||||||
|
void drawBackground(QPainter *painter);
|
||||||
|
void drawText(QPainter *painter);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void setValue(int value); // 设置当前值
|
||||||
|
void setMinValue(int min); // 设置最小值
|
||||||
|
void setMaxValue(int max); // 设置最大值
|
||||||
|
void setRange(int min,int max); // 设置数值范围
|
||||||
|
void setBorderWidth(int width); // 设置边框宽度
|
||||||
|
void setBorderRadio(int radio); // 设置外边框圆角
|
||||||
|
void setInRadio(int radio); // 设置内部绘制区域圆角
|
||||||
|
void setAlarmValue(int alarm); // 设置警告值
|
||||||
|
void setBorderColor(QColor color); // 设置边框颜色
|
||||||
|
int getValue(); // 获取当前值
|
||||||
|
int getMinValue(); // 获取当前最小值
|
||||||
|
int getMaxValue(); // 获取当前最大值
|
||||||
|
int getAlarmValue(); // 获取告警值
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
private:
|
||||||
|
int borderWidth; // 边缘线框宽度
|
||||||
|
int headWidth; // 右侧头部宽度
|
||||||
|
int value; // 当前值
|
||||||
|
int minValue; // 最小值
|
||||||
|
int maxValue; // 最大值
|
||||||
|
int alarmValue; // 警告值
|
||||||
|
int borderRadio; // 外部边框圆角
|
||||||
|
int drawInRadio; // 内部绘制区域圆角
|
||||||
|
QRectF borderRect; // 电池区域
|
||||||
|
QColor borderColor;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // UPGRADEICON_H
|
Loading…
Reference in New Issue