|
|
@@ -10,10 +10,13 @@ MainWidget::MainWidget(QWidget *parent)
|
|
|
{
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
- ui->serialCB->clear();
|
|
|
+ ui->serialCB_3->clear();
|
|
|
m_USBCtrl.SerialPortInit();
|
|
|
connect(Data_Ctrl::getData()->serialPort,SIGNAL(readyRead()),this,SLOT(manual_serialPortReadyRead()));/*手动连接槽函数*/
|
|
|
|
|
|
+ //InitSerial();
|
|
|
+
|
|
|
+
|
|
|
InitUI();
|
|
|
InitConnect();
|
|
|
|
|
|
@@ -25,13 +28,13 @@ MainWidget::MainWidget(QWidget *parent)
|
|
|
});
|
|
|
|
|
|
//QString currentPath = QDir::currentPath();
|
|
|
- m_TotalCHNum=24;
|
|
|
- m_CurPhase=1;
|
|
|
+ m_TotalCHNum=14;
|
|
|
for (int i=0;i<64;i++) {
|
|
|
m_PDUCHInfo[i].CHNum=i+1;
|
|
|
- m_PDUCHInfo[i].CHName.sprintf("CH%d", i+1);
|
|
|
+ m_PDUCHInfo[i].CHName=QString("CH%1").arg(i+1);
|
|
|
+
|
|
|
+ m_chWidget[i].chid=i+1;
|
|
|
}
|
|
|
- InitCHTable(m_TotalCHNum,true);
|
|
|
|
|
|
_timer_update_info = new QTimer(this);
|
|
|
_timer_update_info->setInterval(1000);
|
|
|
@@ -51,7 +54,7 @@ void MainWidget::InitUI()
|
|
|
//通过QSerialPortInfo查找可用串口
|
|
|
foreach(const QSerialPortInfo &info, QSerialPortInfo::availablePorts())
|
|
|
{
|
|
|
- ui->serialCB->addItem(info.portName());
|
|
|
+ ui->serialCB_3->addItem(info.portName());
|
|
|
}
|
|
|
// 发送、接收计数清零
|
|
|
sendNum = 0;
|
|
|
@@ -70,142 +73,58 @@ void MainWidget::InitUI()
|
|
|
lblPortState->setMinimumSize(550, 20);
|
|
|
setNumOnLabel(lblSendNum, "S: ", sendNum);
|
|
|
setNumOnLabel(lblRecvNum, "R: ", recvNum);
|
|
|
+
|
|
|
// 从右往左依次添加
|
|
|
- ui->horizontalLayout_7->addWidget(lblPortState);
|
|
|
- ui->horizontalLayout_7->addWidget(lblSendNum);
|
|
|
- ui->horizontalLayout_7->addWidget(lblRecvNum);
|
|
|
+ ui->horizontalLayout_15->addWidget(lblPortState);
|
|
|
+ ui->horizontalLayout_15->addWidget(lblSendNum);
|
|
|
+ ui->horizontalLayout_15->addWidget(lblRecvNum);
|
|
|
|
|
|
- ui->pushButton_L1->setIcon(QIcon("resource/Started.png"));
|
|
|
- ui->pushButton_L2->setIcon(QIcon("resource/Reset.png"));
|
|
|
- ui->pushButton_L3->setIcon(QIcon("resource/Reset.png"));
|
|
|
+ ui->pb_Debug->setIcon(QIcon(":/resource/Serial.png"));
|
|
|
|
|
|
- ui->pushButton_ALLOPEN->setIcon(QIcon("resource/open.png"));
|
|
|
- ui->pushButton_ALLCLOSE->setIcon(QIcon("resource/close.png"));
|
|
|
-}
|
|
|
-void MainWidget::InitCHTable(int CHNum,bool initFlag)
|
|
|
-{
|
|
|
- if(CHNum>64) return;
|
|
|
+ ui->label_INT->setStyleSheet("color: rgb(0, 218, 205);");
|
|
|
+ ui->label_26->setStyleSheet("color: rgb(0, 218, 205);");
|
|
|
+ ui->label_OUTT->setStyleSheet("color: orange;");
|
|
|
+ ui->label_29->setStyleSheet("color: orange;");
|
|
|
+ // 创建一个 QWidget,并添加一些内容
|
|
|
|
|
|
- if(initFlag)
|
|
|
- {
|
|
|
- ui->tableWidget_CHInfo->setColumnCount(10);
|
|
|
- ui->tableWidget_CHInfo->setRowCount(CHNum);
|
|
|
- QStringList pTableHeadList;
|
|
|
- pTableHeadList<< "通道" << "名称" << "相位" << "电压(V)" << "电流(A)"<< "功率(W)" << "功率因数" << "耗电量(kWh)" << "状态" << "操作";
|
|
|
- ui->tableWidget_CHInfo->setHorizontalHeaderLabels(pTableHeadList);
|
|
|
- ui->tableWidget_CHInfo->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
|
- ui->tableWidget_CHInfo->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
- ui->tableWidget_CHInfo->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
- ui->tableWidget_CHInfo->verticalHeader()->hide();
|
|
|
- ui->tableWidget_CHInfo->setFont(QFont("Helvetica"));
|
|
|
- ui->tableWidget_CHInfo->setColumnWidth(0, 60);
|
|
|
- ui->tableWidget_CHInfo->setColumnWidth(1, 100);
|
|
|
- ui->tableWidget_CHInfo->setColumnWidth(2, 100);
|
|
|
- ui->tableWidget_CHInfo->setColumnWidth(3, 100);
|
|
|
- ui->tableWidget_CHInfo->setColumnWidth(4, 100);
|
|
|
- ui->tableWidget_CHInfo->setColumnWidth(5, 100);
|
|
|
- ui->tableWidget_CHInfo->setColumnWidth(6, 100);
|
|
|
- ui->tableWidget_CHInfo->setColumnWidth(7, 100);
|
|
|
- ui->tableWidget_CHInfo->setColumnWidth(8, 80);
|
|
|
- ui->tableWidget_CHInfo->setColumnWidth(9, 80);
|
|
|
- }
|
|
|
+ ui->gridLayout->setContentsMargins(1, 1, 1, 1);
|
|
|
+ ui->gridLayout->setHorizontalSpacing(20);
|
|
|
+ ui->gridLayout->setVerticalSpacing(8);
|
|
|
+ m_TotalCHNum=14;
|
|
|
+ for (int i=0;i<m_TotalCHNum;i++) {
|
|
|
+ ui->gridLayout->addWidget(&m_chWidget[i], i%((m_TotalCHNum+1)/2), i/((m_TotalCHNum+1)/2));
|
|
|
|
|
|
- ui->tableWidget_CHInfo->clearContents();
|
|
|
- for (int i = 0; i < CHNum;i++)
|
|
|
- {
|
|
|
- ui->tableWidget_CHInfo->setRowHeight(i, 50);
|
|
|
-
|
|
|
- QString chid;
|
|
|
- chid.sprintf("%d", m_PDUCHInfo[i].CHNum);
|
|
|
- QTableWidgetItem *newItem0 = new QTableWidgetItem(chid);
|
|
|
- newItem0->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
- ui->tableWidget_CHInfo->setItem(i, 0, newItem0);
|
|
|
-
|
|
|
- QTableWidgetItem *newItem1 = new QTableWidgetItem(m_PDUCHInfo[i].CHName);
|
|
|
- newItem1->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
- ui->tableWidget_CHInfo->setItem(i, 1, newItem1);
|
|
|
-
|
|
|
- QTableWidgetItem *newItem3;
|
|
|
- if (0 == m_PDUCHInfo[i].CHPhase)
|
|
|
- newItem3 = new QTableWidgetItem("L1");
|
|
|
- else if (1 == m_PDUCHInfo[i].CHPhase)
|
|
|
- newItem3 = new QTableWidgetItem("L2");
|
|
|
- else if (2 == m_PDUCHInfo[i].CHPhase)
|
|
|
- newItem3 = new QTableWidgetItem("L3");
|
|
|
- else newItem3 = new QTableWidgetItem("Null");
|
|
|
- newItem3->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
- ui->tableWidget_CHInfo->setItem(i, 2, newItem3);
|
|
|
-
|
|
|
- QString chV;
|
|
|
- chV.sprintf("%0.3f", m_PDUCHInfo[i].CHVoltage);
|
|
|
- QTableWidgetItem *newItem4 = new QTableWidgetItem(chV);
|
|
|
- newItem4->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
- ui->tableWidget_CHInfo->setItem(i, 3, newItem4);
|
|
|
-
|
|
|
- QString chI;
|
|
|
- chI.sprintf("%0.3f", m_PDUCHInfo[i].CHCurrent);
|
|
|
- QTableWidgetItem *newItem5 = new QTableWidgetItem(chI);
|
|
|
- newItem5->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
- ui->tableWidget_CHInfo->setItem(i, 4, newItem5);
|
|
|
-
|
|
|
- QString chP;
|
|
|
- chP.sprintf("%0.3f", m_PDUCHInfo[i].CHPower);
|
|
|
- QTableWidgetItem *newItem6 = new QTableWidgetItem(chP);
|
|
|
- newItem6->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
- ui->tableWidget_CHInfo->setItem(i, 5, newItem6);
|
|
|
-
|
|
|
- QString chF;
|
|
|
- chF.sprintf("%0.3f", m_PDUCHInfo[i].CHFactor);
|
|
|
- QTableWidgetItem *newItem7 = new QTableWidgetItem(chF);
|
|
|
- newItem7->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
- ui->tableWidget_CHInfo->setItem(i, 6, newItem7);
|
|
|
-
|
|
|
- QString chC;
|
|
|
- chC.sprintf("%0.3f", m_PDUCHInfo[i].CHConsumption);
|
|
|
- QTableWidgetItem *newItem8 = new QTableWidgetItem(chC);
|
|
|
- newItem8->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
- ui->tableWidget_CHInfo->setItem(i, 7, newItem8);
|
|
|
-
|
|
|
- QTableWidgetItem *newItem9;
|
|
|
- if (m_PDUCHInfo[i].CHStatus)
|
|
|
- {
|
|
|
- newItem9=new QTableWidgetItem(QIcon("resource/open.png"), "接通");
|
|
|
- newItem9->setData(Qt::BackgroundRole, QBrush(QColor(0, 255 , 0, 60)));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- newItem9 = new QTableWidgetItem(QIcon("resource/close.png"), "断开");
|
|
|
- newItem9->setData(Qt::BackgroundRole, QBrush(QColor(255, 69,0, 60)));
|
|
|
- }
|
|
|
- newItem9->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
- ui->tableWidget_CHInfo->setItem(i, 8, newItem9);
|
|
|
-
|
|
|
- QPushButton* buttonoper;
|
|
|
- if (m_PDUCHInfo[i].CHStatus)
|
|
|
- buttonoper=new QPushButton(QStringLiteral("OFF"), ui->tableWidget_CHInfo);
|
|
|
- else buttonoper=new QPushButton(QStringLiteral("ON"), ui->tableWidget_CHInfo);
|
|
|
- buttonoper->setFixedSize(60, 23);
|
|
|
- auto cellWidget = new QWidget(this);
|
|
|
- auto layout = new QHBoxLayout(cellWidget);
|
|
|
- layout ->addWidget(buttonoper);
|
|
|
- cellWidget->setLayout(layout);
|
|
|
- ui->tableWidget_CHInfo->setCellWidget(i, 9, cellWidget);
|
|
|
- }
|
|
|
+ }
|
|
|
+ QString styleSheet = "QWidget { background-color: #rgb(11, 17, 45); }";
|
|
|
+ //ui->MainWidget->setStyleSheet(styleSheet);
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
void MainWidget::InitConnect()
|
|
|
{
|
|
|
connect(ui->pb_Debug,SIGNAL(clicked()),this,SLOT(slot_changeDebugMode()));
|
|
|
- connect(ui->Button_checkserial,SIGNAL(clicked()),this,SLOT(on_Button_checkserial_clicked()));
|
|
|
- connect(ui->Button_openserial,SIGNAL(clicked()),this,SLOT(on_Button_openserial_clicked()));
|
|
|
- connect(ui->Button_clearrecive,SIGNAL(clicked()),this,SLOT(on_Button_clearrecive_clicked()));
|
|
|
- connect(ui->Button_tx,SIGNAL(clicked()),this,SLOT(on_Button_tx_clicked()));
|
|
|
- connect(ui->Button_cleartx,SIGNAL(clicked()),this,SLOT(on_Button_cleartx_clicked()));
|
|
|
+ connect(ui->Button_checkserial_3,SIGNAL(clicked()),this,SLOT(on_Button_checkserial_clicked()));
|
|
|
+ connect(ui->Button_openserial_3,SIGNAL(clicked()),this,SLOT(on_Button_openserial_clicked()));
|
|
|
+ connect(ui->Button_clearrecive_3,SIGNAL(clicked()),this,SLOT(on_Button_clearrecive_clicked()));
|
|
|
+ connect(ui->Button_tx_4,SIGNAL(clicked()),this,SLOT(on_Button_tx_clicked()));
|
|
|
+ connect(ui->Button_cleartx_4,SIGNAL(clicked()),this,SLOT(on_Button_cleartx_clicked()));
|
|
|
+}
|
|
|
+
|
|
|
+bool MainWidget::InitSerial()
|
|
|
+{
|
|
|
+ /*
|
|
|
+ QAndroidJniObject javaString = QAndroidJniObject::fromString("ttys1");
|
|
|
+ jboolean res = QAndroidJniObject::callStaticMethod<jboolean>(
|
|
|
+ "usb/USBListActivity",
|
|
|
+ "OpenSerial",
|
|
|
+ "(Ljava/lang/String;)Z",
|
|
|
+ javaString.object<jstring>());
|
|
|
+
|
|
|
+*/
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
void MainWidget::manual_serialPortReadyRead()
|
|
|
{
|
|
|
QByteArray recBuf = Data_Ctrl::getData()->serialPort->readAll();;
|
|
|
@@ -216,8 +135,8 @@ void MainWidget::manual_serialPortReadyRead()
|
|
|
// 状态栏显示计数值
|
|
|
setNumOnLabel(lblRecvNum, "R: ", recvNum);
|
|
|
|
|
|
- if(ui->check_hex_recive->checkState() == false){
|
|
|
- if(ui->check_timestamp->checkState() == Qt::Checked){
|
|
|
+ if(ui->check_hex_recive_3->checkState() == false){
|
|
|
+ if(ui->check_timestamp_3->checkState() == Qt::Checked){
|
|
|
QDateTime nowtime = QDateTime::currentDateTime();
|
|
|
str_rev = "[" + nowtime.toString("yyyy-MM-dd hh:mm:ss") + "] ";
|
|
|
str_rev += QString(recBuf).append("\r\n");
|
|
|
@@ -226,7 +145,7 @@ void MainWidget::manual_serialPortReadyRead()
|
|
|
// 在当前位置插入文本,不会发生换行。如果没有移动光标到文件结尾,会导致文件超出当前界面显示范围,界面也不会向下滚动。
|
|
|
//ui->recvEdit->appendPlainText(buf);
|
|
|
|
|
|
- if(ui->check_changeline->checkState() == Qt::Checked){
|
|
|
+ if(ui->check_changeline_3->checkState() == Qt::Checked){
|
|
|
str_rev = QString(recBuf).append("\r\n");
|
|
|
}
|
|
|
else
|
|
|
@@ -245,7 +164,7 @@ void MainWidget::manual_serialPortReadyRead()
|
|
|
str2 += str1.mid (i,2);
|
|
|
str2 += " ";
|
|
|
}
|
|
|
- if(ui->check_timestamp->checkState() == Qt::Checked)
|
|
|
+ if(ui->check_timestamp_3->checkState() == Qt::Checked)
|
|
|
{
|
|
|
QDateTime nowtime = QDateTime::currentDateTime();
|
|
|
str_rev = "[" + nowtime.toString("yyyy-MM-dd hh:mm:ss") + "] ";
|
|
|
@@ -253,77 +172,77 @@ void MainWidget::manual_serialPortReadyRead()
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if(ui->check_changeline->checkState() == Qt::Checked)
|
|
|
+ if(ui->check_changeline_3->checkState() == Qt::Checked)
|
|
|
str_rev += str2.append("\r\n");
|
|
|
else
|
|
|
str_rev = str2;
|
|
|
|
|
|
}
|
|
|
}
|
|
|
- ui->recive_Edit->insertPlainText(str_rev);
|
|
|
- ui->recive_Edit->moveCursor(QTextCursor::End);
|
|
|
+ ui->recive_Edit_4->insertPlainText(str_rev);
|
|
|
+ ui->recive_Edit_4->moveCursor(QTextCursor::End);
|
|
|
}
|
|
|
|
|
|
void MainWidget::on_Button_openserial_clicked()
|
|
|
{
|
|
|
|
|
|
- if(ui->baudrate_CB->currentText()=="1200")
|
|
|
+ if(ui->baudrate_CB_3->currentText()=="1200")
|
|
|
Data_Ctrl::getData()->baudRate=QSerialPort::Baud1200;
|
|
|
- else if(ui->baudrate_CB->currentText()=="2400")
|
|
|
+ else if(ui->baudrate_CB_3->currentText()=="2400")
|
|
|
Data_Ctrl::getData()->baudRate=QSerialPort::Baud2400;
|
|
|
- else if(ui->baudrate_CB->currentText()=="4800")
|
|
|
+ else if(ui->baudrate_CB_3->currentText()=="4800")
|
|
|
Data_Ctrl::getData()->baudRate=QSerialPort::Baud4800;
|
|
|
- else if(ui->baudrate_CB->currentText()=="9600")
|
|
|
+ else if(ui->baudrate_CB_3->currentText()=="9600")
|
|
|
Data_Ctrl::getData()->baudRate=QSerialPort::Baud9600;
|
|
|
- else if(ui->baudrate_CB->currentText()=="19200")
|
|
|
+ else if(ui->baudrate_CB_3->currentText()=="19200")
|
|
|
Data_Ctrl::getData()->baudRate=QSerialPort::Baud19200;
|
|
|
- else if(ui->baudrate_CB->currentText()=="38400")
|
|
|
+ else if(ui->baudrate_CB_3->currentText()=="38400")
|
|
|
Data_Ctrl::getData()->baudRate=QSerialPort::Baud38400;
|
|
|
- else if(ui->baudrate_CB->currentText()=="57600")
|
|
|
+ else if(ui->baudrate_CB_3->currentText()=="57600")
|
|
|
Data_Ctrl::getData()->baudRate=QSerialPort::Baud57600;
|
|
|
- else if(ui->baudrate_CB->currentText()=="115200")
|
|
|
+ else if(ui->baudrate_CB_3->currentText()=="115200")
|
|
|
Data_Ctrl::getData()->baudRate=QSerialPort::Baud115200;
|
|
|
|
|
|
// 获取串口数据位
|
|
|
- if(ui->databit_CB->currentText()=="8")
|
|
|
+ if(ui->databit_CB_3->currentText()=="8")
|
|
|
Data_Ctrl::getData()->dataBits=QSerialPort::Data5;
|
|
|
- else if(ui->databit_CB->currentText()=="7")
|
|
|
+ else if(ui->databit_CB_3->currentText()=="7")
|
|
|
Data_Ctrl::getData()->dataBits=QSerialPort::Data6;
|
|
|
- else if(ui->databit_CB->currentText()=="6")
|
|
|
+ else if(ui->databit_CB_3->currentText()=="6")
|
|
|
Data_Ctrl::getData()->dataBits=QSerialPort::Data7;
|
|
|
- else if(ui->databit_CB->currentText()=="5")
|
|
|
+ else if(ui->databit_CB_3->currentText()=="5")
|
|
|
Data_Ctrl::getData()->dataBits=QSerialPort::Data8;
|
|
|
|
|
|
// 获取串口停止位
|
|
|
- if(ui->stopbit_CB->currentText()=="1")
|
|
|
+ if(ui->stopbit_CB_3->currentText()=="1")
|
|
|
Data_Ctrl::getData()->stopBits=QSerialPort::OneStop;
|
|
|
- else if(ui->stopbit_CB->currentText()=="1.5")
|
|
|
+ else if(ui->stopbit_CB_3->currentText()=="1.5")
|
|
|
Data_Ctrl::getData()->stopBits=QSerialPort::OneAndHalfStop;
|
|
|
- else if(ui->stopbit_CB->currentText()=="2")
|
|
|
+ else if(ui->stopbit_CB_3->currentText()=="2")
|
|
|
Data_Ctrl::getData()->stopBits=QSerialPort::TwoStop;
|
|
|
|
|
|
// 获取串口奇偶校验位
|
|
|
- if(ui->checkbit_CB->currentText() == "None"){
|
|
|
+ if(ui->checkbit_CB_3->currentText() == "None"){
|
|
|
Data_Ctrl::getData()->checkBits = QSerialPort::NoParity;
|
|
|
- }else if(ui->checkbit_CB->currentText() == "Odd"){
|
|
|
+ }else if(ui->checkbit_CB_3->currentText() == "Odd"){
|
|
|
Data_Ctrl::getData()->checkBits = QSerialPort::OddParity;
|
|
|
- }else if(ui->checkbit_CB->currentText() == "Even"){
|
|
|
+ }else if(ui->checkbit_CB_3->currentText() == "Even"){
|
|
|
Data_Ctrl::getData()->checkBits = QSerialPort::EvenParity;
|
|
|
}
|
|
|
|
|
|
// 初始化串口属性,设置 端口号、波特率、数据位、停止位、奇偶校验位数
|
|
|
- Data_Ctrl::getData()->serialPort->setPortName(ui->serialCB->currentText());
|
|
|
+ Data_Ctrl::getData()->serialPort->setPortName(ui->serialCB_3->currentText());
|
|
|
|
|
|
|
|
|
|
|
|
// 根据初始化好的串口属性,打开串口
|
|
|
// 如果打开成功,反转打开按钮显示和功能。打开失败,无变化,并且弹出错误对话框。
|
|
|
- if(ui->Button_openserial->text() == "打开串口"){
|
|
|
+ if(ui->Button_openserial_3->text() == "打开串口"){
|
|
|
if(m_USBCtrl.SeralPortCtrl(SeralCtrlType::Seral_Open)){
|
|
|
//QMessageBox::
|
|
|
- ui->Button_openserial->setText("关闭串口");
|
|
|
+ ui->Button_openserial_3->setText("关闭串口");
|
|
|
// 让端口号下拉框不可选,避免误操作(选择功能不可用,控件背景为灰色)
|
|
|
- ui->serialCB->setEnabled(false);
|
|
|
+ ui->serialCB_3->setEnabled(false);
|
|
|
}else{
|
|
|
QMessageBox::critical(this, "错误提示", "串口打开失败!!!\r\n该串口可能被占用\r\n请选择正确的串口");
|
|
|
}
|
|
|
@@ -334,9 +253,9 @@ void MainWidget::on_Button_openserial_clicked()
|
|
|
lblPortState->setStyleSheet("color:green");
|
|
|
}else{
|
|
|
m_USBCtrl.SeralPortCtrl(SeralCtrlType::Seral_Close);
|
|
|
- ui->Button_openserial->setText("打开串口");
|
|
|
+ ui->Button_openserial_3->setText("打开串口");
|
|
|
// 端口号下拉框恢复可选,避免误操作
|
|
|
- ui->serialCB->setEnabled(true);
|
|
|
+ ui->serialCB_3->setEnabled(true);
|
|
|
//statusBar 状态栏显示端口状态
|
|
|
QString sm = "%1 CLOSED";
|
|
|
QString status = sm.arg(Data_Ctrl::getData()->serialPort->portName());
|
|
|
@@ -350,15 +269,15 @@ void MainWidget::on_Button_tx_clicked()
|
|
|
QByteArray array;
|
|
|
|
|
|
//Hex复选框
|
|
|
- if(ui->check_hexsend->checkState() == Qt::Checked){
|
|
|
+ if(ui->check_hexsend_4->checkState() == Qt::Checked){
|
|
|
//array = QString2Hex(data); //HEX 16进制
|
|
|
- array = QByteArray::fromHex(ui->send_Edit->toPlainText().toUtf8()).data();
|
|
|
+ array = QByteArray::fromHex(ui->send_Edit_3->toPlainText().toUtf8()).data();
|
|
|
}else{
|
|
|
//array = data.toLatin1(); //ASCII
|
|
|
- array = ui->send_Edit->toPlainText().toLocal8Bit().data();
|
|
|
+ array = ui->send_Edit_3->toPlainText().toLocal8Bit().data();
|
|
|
}
|
|
|
|
|
|
- if(ui->check_sendnewline->checkState() == Qt::Checked){
|
|
|
+ if(ui->check_sendnewline_4->checkState() == Qt::Checked){
|
|
|
array.append("\r\n");
|
|
|
}
|
|
|
// 如发送成功,会返回发送的字节长度。失败,返回-1。
|
|
|
@@ -371,11 +290,22 @@ void MainWidget::on_Button_tx_clicked()
|
|
|
// 状态栏显示计数值
|
|
|
setNumOnLabel(lblSendNum, "S: ", sendNum);
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ QMessageBox::StandardButton confimBtn = QMessageBox::question(this, "确认", " 串口信息发送失败!", QMessageBox::Ok | QMessageBox::Cancel);
|
|
|
+ if (confimBtn == QMessageBox::Cancel) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void MainWidget::on_Button_clearrecive_clicked()
|
|
|
{
|
|
|
- ui->recive_Edit->clear();
|
|
|
+ ui->recive_Edit_4->clear();
|
|
|
// 清除发送、接收字节计数
|
|
|
sendNum = 0;
|
|
|
recvNum = 0;
|
|
|
@@ -386,7 +316,7 @@ void MainWidget::on_Button_clearrecive_clicked()
|
|
|
|
|
|
void MainWidget::on_Button_cleartx_clicked()
|
|
|
{
|
|
|
- ui->recive_Edit->clear();
|
|
|
+ ui->recive_Edit_4->clear();
|
|
|
// 清除发送字节计数
|
|
|
sendNum = 0;
|
|
|
// 状态栏显示计数值
|
|
|
@@ -399,15 +329,15 @@ void MainWidget::on_check_autosend_stateChanged(int arg1)
|
|
|
if(arg1 == 0){
|
|
|
timSend->stop();
|
|
|
// 时间输入框恢复可选
|
|
|
- ui->spin_sendtime->setEnabled(true);
|
|
|
+ ui->spin_sendtime_4->setEnabled(true);
|
|
|
}else{
|
|
|
// 对输入的值做限幅,小于10ms会弹出对话框提示
|
|
|
- if(ui->spin_sendtime->text().toInt() >= 10){
|
|
|
- timSend->start(ui->spin_sendtime->text().toInt());// 设置定时时长,重新计数
|
|
|
+ if(ui->spin_sendtime_4->text().toInt() >= 10){
|
|
|
+ timSend->start(ui->spin_sendtime_4->text().toInt());// 设置定时时长,重新计数
|
|
|
// 让时间输入框不可选,避免误操作(输入功能不可用,控件背景为灰色)
|
|
|
- ui->spin_sendtime->setEnabled(false);
|
|
|
+ ui->spin_sendtime_4->setEnabled(false);
|
|
|
}else{
|
|
|
- ui->check_autosend->setCheckState(Qt::Unchecked);
|
|
|
+ ui->check_autosend_4->setCheckState(Qt::Unchecked);
|
|
|
QMessageBox::critical(this, "错误提示", "定时发送的最小间隔为 10ms\r\n请确保输入的值 >=10");
|
|
|
}
|
|
|
}
|
|
|
@@ -415,23 +345,75 @@ void MainWidget::on_check_autosend_stateChanged(int arg1)
|
|
|
|
|
|
void MainWidget::on_Button_checkserial_clicked()
|
|
|
{
|
|
|
- ui->serialCB->clear();
|
|
|
+ ui->serialCB_3->clear();
|
|
|
//通过QSerialPortInfo查找可用串口
|
|
|
- foreach(const QSerialPortInfo &info, QSerialPortInfo::availablePorts())
|
|
|
+ //foreach(const QSerialPortInfo &info, QSerialPortInfo::availablePorts())
|
|
|
+ //{
|
|
|
+ // ui->serialCB_3->addItem(info.portName());
|
|
|
+ // }
|
|
|
+ QJniObject usbService = QJniObject::getStaticObjectField("android/content/Context",
|
|
|
+ "USB_SERVICE",
|
|
|
+ "Ljava/lang/String;");
|
|
|
+ if (!usbService.isValid())
|
|
|
{
|
|
|
- ui->serialCB->addItem(info.portName());
|
|
|
+ //logger("fail to get usb service");
|
|
|
+ return;
|
|
|
}
|
|
|
+
|
|
|
+ QJniObject appContext = QJniObject(QNativeInterface::QAndroidApplication::context());
|
|
|
+ QJniObject activity = QJniObject(appContext);
|
|
|
+
|
|
|
+ QJniObject usbManager = activity.callObjectMethod("getSystemService",
|
|
|
+ "(Ljava/lang/String;)Ljava/lang/Object;",
|
|
|
+ usbService.object<jstring>());
|
|
|
+ if (!usbManager.isValid())
|
|
|
+ {
|
|
|
+ //logger("fail to get usb manager");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ QJniObject usbDeviceListHashMap = usbManager.callObjectMethod("getDeviceList",
|
|
|
+ "()Ljava/util/HashMap;");
|
|
|
+ QJniObject devListKeySet = usbDeviceListHashMap.callObjectMethod("keySet",
|
|
|
+ "()Ljava/util/Set;");
|
|
|
+ QJniObject devListIter = devListKeySet.callObjectMethod("iterator",
|
|
|
+ "()Ljava/util/Iterator;");
|
|
|
+ jint devListSize = usbDeviceListHashMap.callMethod<jint>("size", "()I");
|
|
|
+
|
|
|
+ QJniObject usbDevObj;
|
|
|
+ QJniObject usbDevObjIter;
|
|
|
+ int vid = 0, pid = 0;
|
|
|
+ QString devName;
|
|
|
+ for (int i = 0; i < devListSize; ++i)
|
|
|
+ {
|
|
|
+ usbDevObjIter = devListIter.callObjectMethod("next",
|
|
|
+ "()Ljava/lang/Object;");
|
|
|
+ usbDevObj = usbDeviceListHashMap.callObjectMethod("get",
|
|
|
+ "(Ljava/lang/Object;)Ljava/lang/Object;",
|
|
|
+ usbDevObjIter.object());
|
|
|
+ vid = usbDevObj.callMethod<jint>("getVendorId", "()I");
|
|
|
+ pid = usbDevObj.callMethod<jint>("getProductId", "()I");
|
|
|
+ //QAndroidJniObject str((usbDevObj.callMethod<jstring>("getDeviceName", "()Ljava/lang/String;"));
|
|
|
+ QJniObject str( usbDevObj.callObjectMethod(
|
|
|
+ "getDeviceName",
|
|
|
+ "()Ljava/lang/String;"
|
|
|
+ ).object<jstring>());
|
|
|
+ devName = str.toString();
|
|
|
+
|
|
|
+ ui->serialCB_3->addItem(devName);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
void MainWidget::slot_changeDebugMode()
|
|
|
{
|
|
|
- int nIndex=ui->stackedWidget->currentIndex();
|
|
|
- if(nIndex<2)
|
|
|
+ int nIndex=ui->stackedWidget_3->currentIndex();
|
|
|
+ if(nIndex<1)
|
|
|
{
|
|
|
- ui->stackedWidget->setCurrentIndex(2);
|
|
|
+ ui->stackedWidget_3->setCurrentIndex(1);
|
|
|
}else
|
|
|
{
|
|
|
- ui->stackedWidget->setCurrentIndex(1);
|
|
|
+ ui->stackedWidget_3->setCurrentIndex(0);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -439,99 +421,101 @@ void MainWidget::setNumOnLabel(QLabel *lbl, QString strS, long num)
|
|
|
{
|
|
|
// 标签显示
|
|
|
QString strN;
|
|
|
- strN.sprintf("%ld", num);
|
|
|
+ strN=QString("CH%1").arg(num);
|
|
|
QString str = strS + strN;
|
|
|
lbl->setText(str);
|
|
|
}
|
|
|
|
|
|
|
|
|
-void MainWidget::on_pushButton_L1_clicked()
|
|
|
-{
|
|
|
- m_CurPhase=1;
|
|
|
- ui->pushButton_L1->setIcon(QIcon("resource/Started.png"));
|
|
|
- ui->pushButton_L2->setIcon(QIcon("resource/Reset.png"));
|
|
|
- ui->pushButton_L3->setIcon(QIcon("resource/Reset.png"));
|
|
|
-}
|
|
|
-
|
|
|
-void MainWidget::on_pushButton_L2_clicked()
|
|
|
+void MainWidget::UpdateStatusInfo()
|
|
|
{
|
|
|
- m_CurPhase=2;
|
|
|
- ui->pushButton_L1->setIcon(QIcon("resource/Reset.png"));
|
|
|
- ui->pushButton_L2->setIcon(QIcon("resource/Started.png"));
|
|
|
- ui->pushButton_L3->setIcon(QIcon("resource/Reset.png"));
|
|
|
-}
|
|
|
|
|
|
-void MainWidget::on_pushButton_L3_clicked()
|
|
|
-{
|
|
|
- m_CurPhase=3;
|
|
|
- ui->pushButton_L1->setIcon(QIcon("resource/Reset.png"));
|
|
|
- ui->pushButton_L2->setIcon(QIcon("resource/Reset.png"));
|
|
|
- ui->pushButton_L3->setIcon(QIcon("resource/Started.png"));
|
|
|
-}
|
|
|
+ QString strTemp;
|
|
|
+ //更新传感器及日期时间
|
|
|
+ m_PDUAllInfo.Sensor_Temperature=24.5;
|
|
|
+ m_PDUAllInfo.Sensor_Humidity=66.72;
|
|
|
+ m_PDUAllInfo.Sensor_INTemperature=82.33;
|
|
|
+ m_PDUAllInfo.Sensor_OUTTemperature=53.89;
|
|
|
|
|
|
-void MainWidget::on_pushButton_ALLOPEN_clicked()
|
|
|
-{
|
|
|
- QMessageBox::StandardButton confimBtn = QMessageBox::question(this, "确认", "是否打开全部通道?", QMessageBox::Ok | QMessageBox::Cancel);
|
|
|
- if (confimBtn == QMessageBox::Cancel) {
|
|
|
- return;
|
|
|
- }
|
|
|
- else
|
|
|
+ strTemp=QString::number(m_PDUAllInfo.Sensor_Temperature, 'f', 2);
|
|
|
+ ui->label_temperature->setText(strTemp);
|
|
|
+ strTemp=QString::number(m_PDUAllInfo.Sensor_Humidity, 'f', 2);
|
|
|
+ ui->label_humidity->setText(strTemp);
|
|
|
+ if(!m_PDUAllInfo.Sensor_WaterImmersion)
|
|
|
{
|
|
|
- return;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-void MainWidget::on_pushButton_ALLCLOSE_clicked()
|
|
|
-{
|
|
|
- QMessageBox::StandardButton confimBtn = QMessageBox::question(this, "确认", "是否关闭全部通道?", QMessageBox::Ok | QMessageBox::Cancel);
|
|
|
- if (confimBtn == QMessageBox::Cancel) {
|
|
|
- return;
|
|
|
+ ui->label_water->setText("未浸入");
|
|
|
+ ui->label_water->setStyleSheet("color: rgb(10, 197, 50);");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- return;
|
|
|
+ ui->label_water->setText("浸入");
|
|
|
+ // 切换颜色
|
|
|
+ QColor currentColor = ui->label_water->palette().color(QPalette::WindowText);
|
|
|
+ if (currentColor == Qt::white) {
|
|
|
+ ui->label_water->setStyleSheet("color: red;");
|
|
|
+ } else {
|
|
|
+ ui->label_water->setStyleSheet("color: white;");
|
|
|
+ }
|
|
|
}
|
|
|
-}
|
|
|
-void MainWidget::UpdateStatusInfo()
|
|
|
-{
|
|
|
- QString strTemp;
|
|
|
- //更新传感器
|
|
|
- strTemp.sprintf("%0.2f", m_PDUAllInfo.Sensor_Temperature);
|
|
|
- ui->label_temperature->setText(strTemp);
|
|
|
- strTemp.sprintf("%0.2f", m_PDUAllInfo.Sensor_Humidity);
|
|
|
- ui->label_humidity->setText(strTemp);
|
|
|
- strTemp.sprintf("%0.2f", m_PDUAllInfo.Sensor_WaterImmersion);//水浸温度
|
|
|
- //ui->label_temperature->setText(strTemp);
|
|
|
- strTemp.sprintf("%0.2f", m_PDUAllInfo.Sensor_INTemperature);//进液温度
|
|
|
- //ui->label_humidity->setText(strTemp);
|
|
|
- strTemp.sprintf("%0.2f", m_PDUAllInfo.Sensor_OUTTemperature);//出液温度
|
|
|
- // ui->label_humidity->setText(strTemp);
|
|
|
|
|
|
- //更新总体电源状态
|
|
|
- if(1==m_CurPhase)
|
|
|
- {
|
|
|
- strTemp.sprintf("%0.3f", m_PDUAllInfo.AllPower_L1);
|
|
|
- ui->lineEdit_TotalPower->setText(strTemp);
|
|
|
- strTemp.sprintf("%0.3f", m_PDUAllInfo.AllConsumption_L1);
|
|
|
- ui->lineEdit_TotalConsumption->setText(strTemp);
|
|
|
+ strTemp=QString::number(m_PDUAllInfo.Sensor_INTemperature, 'f', 2);//进液温度
|
|
|
+ ui->label_INT->setText(strTemp);
|
|
|
+ strTemp=QString::number(m_PDUAllInfo.Sensor_OUTTemperature, 'f', 2);//出液温度
|
|
|
+ ui->label_OUTT->setText(strTemp);
|
|
|
|
|
|
- }
|
|
|
- else if(2==m_CurPhase)
|
|
|
- {
|
|
|
- strTemp.sprintf("%0.3f", m_PDUAllInfo.AllPower_L2);
|
|
|
- ui->lineEdit_TotalPower->setText(strTemp);
|
|
|
- strTemp.sprintf("%0.3f", m_PDUAllInfo.AllConsumption_L2);
|
|
|
- ui->lineEdit_TotalConsumption->setText(strTemp);
|
|
|
+ QDateTime currentDateTime = QDateTime::currentDateTime();
|
|
|
+ QDate currentDate = currentDateTime.date();
|
|
|
+ QTime currentTime = currentDateTime.time();
|
|
|
|
|
|
- }
|
|
|
- else if(3==m_CurPhase)
|
|
|
- {
|
|
|
- strTemp.sprintf("%0.3f", m_PDUAllInfo.AllPower_L3);
|
|
|
- ui->lineEdit_TotalPower->setText(strTemp);
|
|
|
- strTemp.sprintf("%0.3f", m_PDUAllInfo.AllConsumption_L3);
|
|
|
- ui->lineEdit_TotalConsumption->setText(strTemp);
|
|
|
+ // 以字符串形式显示当前日期和时间
|
|
|
+ QString dateString = currentDate.toString("yyyy-MM-dd");
|
|
|
+ QString timeString = currentTime.toString("HH:mm:ss");
|
|
|
+ ui->label_Date->setText(dateString);
|
|
|
+ ui->label_Time->setText(timeString);
|
|
|
+
|
|
|
+
|
|
|
+ //更新总体电源状态
|
|
|
+ m_PDUAllInfo.AllVoltage_L1+=0.2;
|
|
|
+ m_PDUAllInfo.AllVoltage_L2+=0.6;
|
|
|
+ m_PDUAllInfo.AllVoltage_L3+=0.3;
|
|
|
+ m_PDUAllInfo.AllCurrent_L1+=0.1;
|
|
|
+ m_PDUAllInfo.AllCurrent_L2+=0.2;
|
|
|
+ m_PDUAllInfo.AllCurrent_L3+=0.3;
|
|
|
+ m_PDUAllInfo.AllPower_L1+=0.01;
|
|
|
+ m_PDUAllInfo.AllPower_L2+=0.02;
|
|
|
+ m_PDUAllInfo.AllPower_L3+=0.03;
|
|
|
+ m_PDUAllInfo.AllConsumption_L1+=0.05;
|
|
|
+ m_PDUAllInfo.AllConsumption_L2+=0.09;
|
|
|
+ m_PDUAllInfo.AllConsumption_L3+=0.03;
|
|
|
+
|
|
|
+
|
|
|
+ strTemp=QString::number(m_PDUAllInfo.AllVoltage_L1, 'f', 2);
|
|
|
+ ui->label_V1->setText(strTemp);
|
|
|
+ strTemp=QString::number(m_PDUAllInfo.AllCurrent_L1, 'f', 2);
|
|
|
+ ui->label_I1->setText(strTemp);
|
|
|
+ strTemp=QString::number(m_PDUAllInfo.AllPower_L1, 'f', 2);
|
|
|
+ //ui->label_P1->setText(strTemp);
|
|
|
+ strTemp=QString::number(m_PDUAllInfo.AllConsumption_L1, 'f', 2);
|
|
|
+ //ui->label_C1->setText(strTemp);
|
|
|
+
|
|
|
+ strTemp=QString::number(m_PDUAllInfo.AllVoltage_L2, 'f', 2);
|
|
|
+ ui->label_V2->setText(strTemp);
|
|
|
+ strTemp=QString::number(m_PDUAllInfo.AllCurrent_L2, 'f', 2);
|
|
|
+ ui->label_I2->setText(strTemp);
|
|
|
+ strTemp=QString::number(m_PDUAllInfo.AllPower_L2, 'f', 2);
|
|
|
+ //ui->label_P2->setText(strTemp);
|
|
|
+ strTemp=QString::number(m_PDUAllInfo.AllConsumption_L2, 'f', 2);
|
|
|
+ //ui->label_C2->setText(strTemp);
|
|
|
+
|
|
|
+ strTemp=QString::number(m_PDUAllInfo.AllVoltage_L3, 'f', 2);
|
|
|
+ ui->label_V3->setText(strTemp);
|
|
|
+ strTemp=QString::number(m_PDUAllInfo.AllCurrent_L3, 'f', 2);
|
|
|
+ ui->label_I3->setText(strTemp);
|
|
|
+ strTemp=QString::number(m_PDUAllInfo.AllPower_L3, 'f', 2);
|
|
|
+ //ui->label_P3->setText(strTemp);
|
|
|
+ strTemp=QString::number(m_PDUAllInfo.AllConsumption_L3, 'f', 2);
|
|
|
+ //ui->label_C3->setText(strTemp);
|
|
|
|
|
|
- }
|
|
|
|
|
|
//更新通道信息
|
|
|
for (int i=0;i<64;i++) {
|
|
|
@@ -542,6 +526,14 @@ void MainWidget::UpdateStatusInfo()
|
|
|
m_PDUCHInfo[i].CHFactor=0.983;
|
|
|
if(i%2==0)m_PDUCHInfo[i].CHStatus=true;
|
|
|
}
|
|
|
- InitCHTable(m_TotalCHNum,false);
|
|
|
-}
|
|
|
|
|
|
+
|
|
|
+ for (int i=0;i<m_TotalCHNum;i++) {
|
|
|
+ m_chWidget[i].chid=i+1;
|
|
|
+ m_chWidget[i].chV=m_PDUCHInfo[i].CHVoltage;
|
|
|
+ m_chWidget[i].chI=m_PDUCHInfo[i].CHCurrent;
|
|
|
+ m_chWidget[i].chStatus=m_PDUCHInfo[i].CHStatus;
|
|
|
+ m_chWidget[i].UpdateStatusInfo();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|