#include "mainwindow.h" #include "ui_mainwindow.h" #include #include #include #include #include #include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); Init(); } MainWindow::~MainWindow() { delete ui; } void MainWindow::openFile() { if (ui->openFile->text() == "打开文件") { //选择导入的文件路径 loadpath = QFileDialog::getOpenFileName(this,"选择文件","/", "Files(*.json)"); qDebug() << loadpath << endl; if(loadpath.isEmpty()) return; jsonModel->loadJson(loadpath); ui->treeView->expandAll(); ui->openFile->setText("保存文件"); openFileFlag = true; if (openFileFlag && openSerialPortFlag) { ui->readConfigFile->setEnabled(true); ui->writeConfigFile->setEnabled(true); } else { ui->readConfigFile->setEnabled(false); ui->writeConfigFile->setEnabled(false); } } else { if(loadpath.isEmpty()) return; jsonModel->dumpJson(loadpath); } } void MainWindow::scanSerialPort() { /* 查找可用串口 */ foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) { // ui->SerialPort->addItem(info.portName()); ui->SerialPort->addItem(info.portName() + ":" +info.description()); } } void MainWindow::parityItemInit() { QList list; list<<"None"<<"Even"<<"Odd"<<"Space"<<"Mark"; for (int i = 0; i < 5; i++) { ui->comboBox_4->addItem(list[i]); } ui->comboBox_4->setCurrentIndex(0); } void MainWindow::Init() { ui->readConfigFile->setEnabled(false); ui->writeConfigFile->setEnabled(false); scanSerialPort(); parityItemInit(); serialPort = new QSerialPort(this); jsonModel = new JsonTreeModel(this); ui->treeView->setModel(jsonModel); openSerialPortFlag = false; openFileFlag = false; connect(ui->openFile,SIGNAL(clicked()),this,SLOT(openFile())); connect(ui->SerialPortPushButton,SIGNAL(clicked()) ,this,SLOT(openSerialPortPushButtonClicked())); connect(ui->readConfigFile,SIGNAL(clicked()) ,this,SLOT(readCfgFile())); connect(ui->writeConfigFile,SIGNAL(clicked()) ,this,SLOT(writeCfgFile())); } uint16_t MainWindow::modbusCrc(uint8_t *arr_buff, uint8_t len) { uint16_t crc=0xFFFF; uint16_t i, j; for ( j=0; j0){ crc=crc>>1; crc=crc^ 0xa001; }else{ crc=crc>>1; } } } return crc; } void MainWindow::openSerialPortPushButtonClicked() { if (ui->SerialPortPushButton->text() == "打开串口") { /* 设置串口名 */ // serialPort->setPortName(ui->SerialPort->currentText()); serialPort->setPort((const QSerialPortInfo)(ui->SerialPort->currentText().section(':', 0, 0))); /* 设置波特率 */ serialPort->setBaudRate(ui->comboBox_2->currentText().toInt()); /* 设置数据位数 */ switch (ui->comboBox_3->currentText().toInt()) { case 5: serialPort->setDataBits(QSerialPort::Data5); break; case 6: serialPort->setDataBits(QSerialPort::Data6); break; case 7: serialPort->setDataBits(QSerialPort::Data7); break; case 8: serialPort->setDataBits(QSerialPort::Data8); break; default: break; } /* 设置奇偶校验 */ switch (ui->comboBox_4->currentIndex()) { case 0: serialPort->setParity(QSerialPort::NoParity); break; case 1: serialPort->setParity(QSerialPort::EvenParity); break; case 2: serialPort->setParity(QSerialPort::OddParity); break; case 3: serialPort->setParity(QSerialPort::SpaceParity); break; case 4: serialPort->setParity(QSerialPort::MarkParity); break; default: break; } /* 设置停止位 */ switch (ui->comboBox_5->currentText().toInt()) { case 1: serialPort->setStopBits(QSerialPort::OneStop); break; case 2: serialPort->setStopBits(QSerialPort::TwoStop); break; default: break; } /* 设置流控制 */ serialPort->setFlowControl(QSerialPort::NoFlowControl); if (!serialPort->open(QIODevice::ReadWrite)) QMessageBox::about(NULL, "错误", "串口无法打开!可能串口已经被占用!"); else { ui->SerialPort->setEnabled(false); ui->comboBox_2->setEnabled(false); ui->comboBox_3->setEnabled(false); ui->comboBox_4->setEnabled(false); ui->comboBox_5->setEnabled(false); ui->SerialPortPushButton->setText("关闭串口"); ui->label_6->setStyleSheet("color: red;"); // pushButton[0]->setEnabled(true); openSerialPortFlag = true; if (openFileFlag && openSerialPortFlag) { ui->readConfigFile->setEnabled(true); ui->writeConfigFile->setEnabled(true); } else { ui->readConfigFile->setEnabled(false); ui->writeConfigFile->setEnabled(false); } } } else { serialPort->close(); ui->SerialPort->setEnabled(true); ui->comboBox_2->setEnabled(true); ui->comboBox_3->setEnabled(true); ui->comboBox_4->setEnabled(true); ui->comboBox_5->setEnabled(true); ui->label_6->setStyleSheet("color: block;"); ui->SerialPortPushButton->setText("打开串口"); openSerialPortFlag = false; if (openFileFlag && openSerialPortFlag) { ui->readConfigFile->setEnabled(true); ui->writeConfigFile->setEnabled(true); } else { ui->readConfigFile->setEnabled(false); ui->writeConfigFile->setEnabled(false); } } } void MainWindow::readCfgFile() { qDebug(" in readCfgFile "); uint8_t readCfgBuf[256]; uint8_t *readCfgPoint = readCfgBuf; /* 起始标志 */ *readCfgPoint = 'S'; readCfgPoint += 1; *readCfgPoint = 'L'; readCfgPoint += 1; /* 唯一ID */ // QJsonDocument json_doc; // 判断是否解析失败 // if (jsonModel->readJson() != true || !json_doc.isNull()) { // if (!jsonModel->readJson() || !jsonModel->json_doc.isNull()) { // qDebug() << "Json格式错误!" ; // return; // } /* 唯一ID */ bool flag = jsonModel->readJson(); if (!flag) { qDebug() << "Json格式错误1!" ; return; } if (jsonModel->json_doc.isNull()) { qDebug() << "Json格式错误2!" ; return; } /* 获取根 { } */ // QJsonObject rootObj = json_doc.object(); if (!jsonModel->json_doc.isObject()) { qDebug() << "json_doc.isObject()" ; } QJsonValue tempValue = jsonModel->json_doc.object().value("充电控制盒配置文件"); // QJsonValue tempValue = rootObj.value("充电控制盒配置文件"); // QJsonValue tempValue = rootObj.value("chargeControlCfgFile"); QJsonObject tempObject; QJsonObject rootObj; if (tempValue.isObject()) { rootObj = tempValue.toObject(); } else { qDebug() << "充电控制盒配置文件 error" << tempValue.type() ; return; } tempValue = rootObj.value("设备的唯一地址"); if (tempValue.isObject()) { tempObject = tempValue.toObject(); } else { qDebug() << "onlyID object error" << tempValue.type() ; return; } tempValue = tempObject.value("unique_Device_ID"); QJsonArray tempArray; if (tempValue.isArray()) { tempArray = tempValue.toArray(); } else { qDebug() << "onlyID object error" << tempValue.type() ; return; } QString tempString = tempArray.at(0).toString(); tempString.remove("0x"); // 将字符串转换为整数(基数为 16) bool ok; *readCfgPoint = tempString.toInt(&ok, 16); readCfgPoint += 1; // readCfgBuf[2] = tempString.toInt(&ok, 16); if (!ok) { qDebug() << "转换失败!"; return; } tempString = tempArray.at(1).toString(); tempString.remove("0x"); // 将字符串转换为整数(基数为 16) // readCfgBuf[3] = tempString.toInt(&ok, 16); *readCfgPoint = tempString.toInt(&ok, 16); readCfgPoint += 1; if (!ok) { qDebug() << "转换失败!"; return; } tempString = tempArray.at(2).toString(); tempString.remove("0x"); // 将字符串转换为整数(基数为 16) // readCfgBuf[4] = tempString.toInt(&ok, 16); *readCfgPoint = tempString.toInt(&ok, 16); readCfgPoint += 1; if (!ok) { qDebug() << "转换失败!"; return; } tempString = tempArray.at(3).toString(); tempString.remove("0x"); // 将字符串转换为整数(基数为 16) // readCfgBuf[5] = tempString.toInt(&ok, 16); *readCfgPoint = tempString.toInt(&ok, 16); readCfgPoint += 1; if (!ok) { qDebug() << "转换失败!"; return; } tempString = tempArray.at(4).toString(); tempString.remove("0x"); // 将字符串转换为整数(基数为 16) // readCfgBuf[6] = tempString.toInt(&ok, 16); *readCfgPoint = tempString.toInt(&ok, 16); readCfgPoint += 1; if (!ok) { qDebug() << "转换失败!"; return; } tempString = tempArray.at(5).toString(); tempString.remove("0x"); // 将字符串转换为整数(基数为 16) // readCfgBuf[7] = tempString.toInt(&ok, 16); *readCfgPoint = tempString.toInt(&ok, 16); readCfgPoint += 1; if (!ok) { qDebug() << "转换失败!"; return; } tempString = tempArray.at(6).toString(); tempString.remove("0x"); // 将字符串转换为整数(基数为 16) // readCfgBuf[8] = tempString.toInt(&ok, 16); *readCfgPoint = tempString.toInt(&ok, 16); readCfgPoint += 1; if (!ok) { qDebug() << "转换失败!"; return; } // qDebug(" 0x%x ", readCfgBuf[0]); // qDebug(" 0x%x ", readCfgBuf[1]); // qDebug(" 0x%x ", readCfgBuf[2]); // qDebug(" 0x%x ", readCfgBuf[3]); // qDebug(" 0x%x ", readCfgBuf[4]); // qDebug(" 0x%x ", readCfgBuf[5]); // qDebug(" 0x%x ", readCfgBuf[6]); // qDebug(" 0x%x ", readCfgBuf[7]); // qDebug(" 0x%x ", readCfgBuf[8]); /* 功能码 */ // readCfgBuf[9] = 0xD1; *readCfgPoint = 0xD1; readCfgPoint += 1; /* 数据长度 */ *readCfgPoint = 60 >> 8; readCfgPoint += 1; *readCfgPoint = 60; readCfgPoint += 1; /* 数据内容 */ *readCfgPoint = (uint8_t)(0x0000 >> 8); readCfgPoint += 1; *readCfgPoint = (uint8_t)0x0000; readCfgPoint += 1; *readCfgPoint = (uint8_t)(0x0001 >> 8); readCfgPoint += 1; *readCfgPoint = (uint8_t)0x0001; readCfgPoint += 1; *readCfgPoint = (uint8_t)(0x0002 >> 8); readCfgPoint += 1; *readCfgPoint = (uint8_t)0x0002; readCfgPoint += 1; *readCfgPoint = (uint8_t)(0x0100 >> 8); readCfgPoint += 1; *readCfgPoint = (uint8_t)0x0100; readCfgPoint += 1; *readCfgPoint = (uint8_t)(0x0101 >> 8); readCfgPoint += 1; *readCfgPoint = (uint8_t)0x0101; readCfgPoint += 1; *readCfgPoint = (uint8_t)(0x0102 >> 8); readCfgPoint += 1; *readCfgPoint = (uint8_t)0x0102; readCfgPoint += 1; *readCfgPoint = (uint8_t)(0x0103 >> 8); readCfgPoint += 1; *readCfgPoint = (uint8_t)0x0103; readCfgPoint += 1; *readCfgPoint = (uint8_t)(0x0104 >> 8); readCfgPoint += 1; *readCfgPoint = (uint8_t)0x0104; readCfgPoint += 1; *readCfgPoint = (uint8_t)(0x0105 >> 8); readCfgPoint += 1; *readCfgPoint = (uint8_t)0x0105; readCfgPoint += 1; *readCfgPoint = (uint8_t)(0x0106 >> 8); readCfgPoint += 1; *readCfgPoint = (uint8_t)0x0106; readCfgPoint += 1; *readCfgPoint = (uint8_t)(0x0107 >> 8); readCfgPoint += 1; *readCfgPoint = (uint8_t)0x0107; readCfgPoint += 1; *readCfgPoint = (uint8_t)(0x0108 >> 8); readCfgPoint += 1; *readCfgPoint = (uint8_t)0x0108; readCfgPoint += 1; *readCfgPoint = (uint8_t)(0x0109 >> 8); readCfgPoint += 1; *readCfgPoint = (uint8_t)0x0109; readCfgPoint += 1; *readCfgPoint = (uint8_t)(0x010A >> 8); readCfgPoint += 1; *readCfgPoint = (uint8_t)0x010A; readCfgPoint += 1; *readCfgPoint = (uint8_t)(0x010B >> 8); readCfgPoint += 1; *readCfgPoint = (uint8_t)0x010B; readCfgPoint += 1; *readCfgPoint = (uint8_t)(0x010C >> 8); readCfgPoint += 1; *readCfgPoint = (uint8_t)0x010C; readCfgPoint += 1; *readCfgPoint = (uint8_t)(0x010D >> 8); readCfgPoint += 1; *readCfgPoint = (uint8_t)0x010D; readCfgPoint += 1; *readCfgPoint = (uint8_t)(0x010E >> 8); readCfgPoint += 1; *readCfgPoint = (uint8_t)0x010E; readCfgPoint += 1; *readCfgPoint = (uint8_t)(0x010F >> 8); readCfgPoint += 1; *readCfgPoint = (uint8_t)0x010F; readCfgPoint += 1; *readCfgPoint = (uint8_t)(0x0110 >> 8); readCfgPoint += 1; *readCfgPoint = (uint8_t)0x0110; readCfgPoint += 1; *readCfgPoint = (uint8_t)(0x0111 >> 8); readCfgPoint += 1; *readCfgPoint = (uint8_t)0x0111; readCfgPoint += 1; *readCfgPoint = (uint8_t)(0x0112 >> 8); readCfgPoint += 1; *readCfgPoint = (uint8_t)0x0112; readCfgPoint += 1; *readCfgPoint = (uint8_t)(0x0113 >> 8); readCfgPoint += 1; *readCfgPoint = (uint8_t)0x0113; readCfgPoint += 1; *readCfgPoint = (uint8_t)(0x0114 >> 8); readCfgPoint += 1; *readCfgPoint = (uint8_t)0x0114; readCfgPoint += 1; *readCfgPoint = (uint8_t)(0x0115 >> 8); readCfgPoint += 1; *readCfgPoint = (uint8_t)0x0115; readCfgPoint += 1; *readCfgPoint = (uint8_t)(0x0116 >> 8); readCfgPoint += 1; *readCfgPoint = (uint8_t)0x0116; readCfgPoint += 1; *readCfgPoint = (uint8_t)(0x0117 >> 8); readCfgPoint += 1; *readCfgPoint = (uint8_t)0x0117; readCfgPoint += 1; *readCfgPoint = (uint8_t)(0x0118 >> 8); readCfgPoint += 1; *readCfgPoint = (uint8_t)0x0118; readCfgPoint += 1; *readCfgPoint = (uint8_t)(0x0119 >> 8); readCfgPoint += 1; *readCfgPoint = (uint8_t)0x0119; readCfgPoint += 1; *readCfgPoint = (uint8_t)(0x011A >> 8); readCfgPoint += 1; *readCfgPoint = (uint8_t)0x011A; readCfgPoint += 1; /* crc校验 */ uint16_t tempU16 = 0; tempU16 = modbusCrc(readCfgBuf, (60 + 12)); *readCfgPoint = (uint8_t)(tempU16 >> 8); readCfgPoint += 1; *readCfgPoint = (uint8_t)tempU16; readCfgPoint += 1; /* 结束标志 */ *readCfgPoint = 0x16; // for (int i = 0; i < 29 * 2 + 12 + 3; i++) { // qDebug(" 0x%x ", readCfgBuf[i]); // } // /* 设备的唯一地址 */ // tempValue = rootObj.value("设备的唯一地址"); // if (tempValue.isObject()) { // tempObject = tempValue.toObject(); // } // else { // qDebug() << "设备的唯一地址 error" << tempValue.type() ; // return; // } // tempValue = tempObject.value("类型"); // if (tempValue.isString()) { // tempString = tempValue.toString(); // } // else { // qDebug() << "设备的唯一地址 error" << tempValue.type() ; // return; // } // tempString.remove("H"); // // 将字符串转换为整数(基数为 16) //// readCfgBuf[11] = tempString.toInt(&ok, 16); // *readCfgPoint = tempString.toInt(&ok, 16); // readCfgPoint += 1; // if (!ok) { // qDebug() << "转换失败!"; // return; // } // readCfgBuf[10] = 0; // readCfgBuf[10]++; //// qDebug(" 0x%x ", readCfgBuf[11]); // /* 对上通讯波特率 */ // tempValue = rootObj.value("SL协议对上通信波特率"); // if (tempValue.isObject()) { // tempObject = tempValue.toObject(); // } // else { // qDebug() << "SL协议对上通信波特率error" << tempValue.type() ; // return; // } // tempValue = tempObject.value("类型"); // if (tempValue.isString()) { // tempString = tempValue.toString(); // } // else { // qDebug() << "SL协议对上通信波特率类型 error" << tempValue.type() ; // return; // } // tempString.remove("H"); // // 将字符串转换为整数(基数为 16) // readCfgBuf[11] = tempString.toInt(&ok, 16); // if (!ok) { // qDebug() << "转换失败!"; // return; // } // readCfgBuf[10]++; //// qDebug(" 0x%x ", readCfgBuf[11]); // /* SL协议对下通信波特率 */ // tempValue = rootObj.value("SL协议对下通信波特率"); // if (tempValue.isObject()) { // tempObject = tempValue.toObject(); // } // else { // qDebug() << "SL协议对下通信波特率 error" << tempValue.type() ; // return; // } // tempValue = tempObject.value("类型"); // if (tempValue.isString()) { // tempString = tempValue.toString(); // } // else { // qDebug() << "SL协议对下通信波特率 error" << tempValue.type() ; // return; // } // tempString.remove("H"); // // 将字符串转换为整数(基数为 16) // readCfgBuf[11] = tempString.toInt(&ok, 16); // if (!ok) { // qDebug() << "转换失败!"; // return; // } // readCfgBuf[10]++; ui->SerialPortPushButton->setDisabled(true); ui->readConfigFile->setDisabled(true); ui->writeConfigFile->setDisabled(true); serialPort->write(reinterpret_cast(readCfgBuf), (60 + 12 + 3)); /* 延时1.5S */ QThread::msleep(1500); QByteArray data = serialPort->readAll(); // if (data.length() < 17) { // goto error; // } /* 起始标志 */ uint8_t *repData = (uint8_t *)data.data(); if (*repData != 'S' || *(repData + 1) != 'L') { goto error; } // /* 地址 */ // if (data.at(0) != 'S' || data.at(1) != 'L') { // goto error; // } if (*(repData + 9) != 0xD0) { goto error; } // uint16_t crc16 = modbusCrc(repData, 14); // return; error: ui->SerialPortPushButton->setEnabled(true); ui->readConfigFile->setEnabled(true); ui->writeConfigFile->setEnabled(true); } void MainWindow::writeCfgFile() { qDebug(" in writeCfgFile "); uint8_t writeCfgBuf[256]; uint8_t *writeCfgPoint = writeCfgBuf; /* 起始标志 */ *writeCfgPoint = 'S'; writeCfgPoint += 1; *writeCfgPoint = 'L'; writeCfgPoint += 1; /* 唯一ID */ // QJsonDocument json_doc; // 判断是否解析失败 // if (jsonModel->readJson() != true || !json_doc.isNull()) { // if (!jsonModel->readJson() || !jsonModel->json_doc.isNull()) { // qDebug() << "Json格式错误!" ; // return; // } /* 唯一ID */ bool flag = jsonModel->readJson(); if (!flag) { qDebug() << "Json格式错误1!" ; return; } if (jsonModel->json_doc.isNull()) { qDebug() << "Json格式错误2!" ; return; } /* 获取根 { } */ // QJsonObject rootObj = json_doc.object(); if (!jsonModel->json_doc.isObject()) { qDebug() << "json_doc.isObject()" ; } QJsonValue tempValue = jsonModel->json_doc.object().value("充电控制盒配置文件"); // QJsonValue tempValue = rootObj.value("充电控制盒配置文件"); // QJsonValue tempValue = rootObj.value("chargeControlCfgFile"); QJsonObject tempObject; QJsonObject rootObj; if (tempValue.isObject()) { rootObj = tempValue.toObject(); } else { qDebug() << "充电控制盒配置文件 error" << tempValue.type() ; return; } tempValue = rootObj.value("设备的唯一地址"); if (tempValue.isObject()) { tempObject = tempValue.toObject(); } else { qDebug() << "onlyID object error" << tempValue.type() ; return; } tempValue = tempObject.value("unique_Device_ID"); QJsonArray tempArray; if (tempValue.isArray()) { tempArray = tempValue.toArray(); } else { qDebug() << "onlyID object error" << tempValue.type() ; return; } QString tempString = tempArray.at(0).toString(); tempString.remove("0x"); // 将字符串转换为整数(基数为 16) bool ok; *writeCfgPoint = tempString.toInt(&ok, 16); writeCfgPoint += 1; // readCfgBuf[2] = tempString.toInt(&ok, 16); if (!ok) { qDebug() << "转换失败!"; return; } tempString = tempArray.at(1).toString(); tempString.remove("0x"); // 将字符串转换为整数(基数为 16) // readCfgBuf[3] = tempString.toInt(&ok, 16); *writeCfgPoint = tempString.toInt(&ok, 16); writeCfgPoint += 1; if (!ok) { qDebug() << "转换失败!"; return; } tempString = tempArray.at(2).toString(); tempString.remove("0x"); // 将字符串转换为整数(基数为 16) // readCfgBuf[4] = tempString.toInt(&ok, 16); *writeCfgPoint = tempString.toInt(&ok, 16); writeCfgPoint += 1; if (!ok) { qDebug() << "转换失败!"; return; } tempString = tempArray.at(3).toString(); tempString.remove("0x"); // 将字符串转换为整数(基数为 16) // readCfgBuf[5] = tempString.toInt(&ok, 16); *writeCfgPoint = tempString.toInt(&ok, 16); writeCfgPoint += 1; if (!ok) { qDebug() << "转换失败!"; return; } tempString = tempArray.at(4).toString(); tempString.remove("0x"); // 将字符串转换为整数(基数为 16) // readCfgBuf[6] = tempString.toInt(&ok, 16); *writeCfgPoint = tempString.toInt(&ok, 16); writeCfgPoint += 1; if (!ok) { qDebug() << "转换失败!"; return; } tempString = tempArray.at(5).toString(); tempString.remove("0x"); // 将字符串转换为整数(基数为 16) // readCfgBuf[7] = tempString.toInt(&ok, 16); *writeCfgPoint = tempString.toInt(&ok, 16); writeCfgPoint += 1; if (!ok) { qDebug() << "转换失败!"; return; } tempString = tempArray.at(6).toString(); tempString.remove("0x"); // 将字符串转换为整数(基数为 16) // readCfgBuf[8] = tempString.toInt(&ok, 16); *writeCfgPoint = tempString.toInt(&ok, 16); writeCfgPoint += 1; if (!ok) { qDebug() << "转换失败!"; return; } /* 功能码 */ *writeCfgPoint = 0xD0; writeCfgPoint += 1; /* 帧编号 */ *writeCfgPoint = 1; writeCfgPoint += 1; /* 总帧数 */ *writeCfgPoint = 1; writeCfgPoint += 1; /* 数据长度 */ uint16_t dataLen = 0; writeCfgPoint += 2; /* 数据内容 */ /* 更改设备的唯一地址 */ tempValue = rootObj.value("更改设备的唯一地址"); /* if (tempValue.isObject()) { tempObject = tempValue.toObject(); } else { qDebug() << "更改设备的唯一地址 error" << tempValue.type() ; return; }*/ tempValue = tempObject.value("类型"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "更改设备的唯一地址 error" << tempValue.type() ; return; } tempString.remove("H"); // 将字符串转换为整数(基数为 16) uint16_t tempU16 = tempString.toInt(&ok, 16); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; tempValue = rootObj.value("更改设备的唯一地址"); tempValue = tempObject.value("unique_Device_ID"); if (tempValue.isArray()) { tempArray = tempValue.toArray(); } else { qDebug() << "更改设备的唯一地址 error" << tempValue.type() ; return; } tempString = tempArray.at(0).toString(); tempString.remove("0x"); *writeCfgPoint = tempString.toInt(&ok, 16); writeCfgPoint += 1; if (!ok) { qDebug() << "转换失败!"; return; } tempString = tempArray.at(1).toString(); tempString.remove("0x"); // 将字符串转换为整数(基数为 16) // readCfgBuf[3] = tempString.toInt(&ok, 16); *writeCfgPoint = tempString.toInt(&ok, 16); writeCfgPoint += 1; if (!ok) { qDebug() << "转换失败!"; return; } tempString = tempArray.at(2).toString(); tempString.remove("0x"); // 将字符串转换为整数(基数为 16) // readCfgBuf[4] = tempString.toInt(&ok, 16); *writeCfgPoint = tempString.toInt(&ok, 16); writeCfgPoint += 1; if (!ok) { qDebug() << "转换失败!"; return; } tempString = tempArray.at(3).toString(); tempString.remove("0x"); // 将字符串转换为整数(基数为 16) // readCfgBuf[5] = tempString.toInt(&ok, 16); *writeCfgPoint = tempString.toInt(&ok, 16); writeCfgPoint += 1; if (!ok) { qDebug() << "转换失败!"; return; } tempString = tempArray.at(4).toString(); tempString.remove("0x"); // 将字符串转换为整数(基数为 16) // readCfgBuf[6] = tempString.toInt(&ok, 16); *writeCfgPoint = tempString.toInt(&ok, 16); writeCfgPoint += 1; if (!ok) { qDebug() << "转换失败!"; return; } tempString = tempArray.at(5).toString(); tempString.remove("0x"); // 将字符串转换为整数(基数为 16) // readCfgBuf[7] = tempString.toInt(&ok, 16); *writeCfgPoint = tempString.toInt(&ok, 16); writeCfgPoint += 1; if (!ok) { qDebug() << "转换失败!"; return; } tempString = tempArray.at(6).toString(); tempString.remove("0x"); // 将字符串转换为整数(基数为 16) // readCfgBuf[8] = tempString.toInt(&ok, 16); *writeCfgPoint = tempString.toInt(&ok, 16); writeCfgPoint += 1; if (!ok) { qDebug() << "转换失败!"; return; } dataLen += 7; /* SL协议对上通信波特率 */ tempValue = rootObj.value("SL协议对上通信波特率"); if (tempValue.isObject()) { tempObject = tempValue.toObject(); } else { qDebug() << "SL协议对上通信波特率 error" << tempValue.type() ; return; } tempValue = tempObject.value("类型"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "更改设备的唯一地址 error" << tempValue.type() ; return; } tempString.remove("H"); // 将字符串转换为整数(基数为 16) tempU16 = tempString.toInt(&ok, 16); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; tempValue = rootObj.value("SL协议对上通信波特率"); tempValue = tempObject.value("SL_Protocol_Communication_Baud_Rate_Up"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "SL_Protocol_Communication_Baud_Rate_Up error" << tempValue.type() ; return; } tempString.remove("0x"); *writeCfgPoint = tempString.toInt(&ok, 16); writeCfgPoint += 1; dataLen += 1; /* SL协议对下通信波特率 */ tempValue = rootObj.value("SL协议对下通信波特率"); if (tempValue.isObject()) { tempObject = tempValue.toObject(); } else { qDebug() << "SL协议对下通信波特率 error" << tempValue.type() ; return; } tempValue = tempObject.value("类型"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "类型 error" << tempValue.type() ; return; } tempString.remove("H"); // 将字符串转换为整数(基数为 16) tempU16 = tempString.toInt(&ok, 16); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; tempValue = rootObj.value("SL协议对下通信波特率"); tempValue = tempObject.value("SL_Protocol_Communication_Baud_Rate_Down"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "SL_Protocol_Communication_Baud_Rate_Down error" << tempValue.type() ; return; } tempString.remove("0x"); *writeCfgPoint = tempString.toInt(&ok, 16); writeCfgPoint += 1; dataLen += 1; /* 电源盒类型 */ tempValue = rootObj.value("电源盒类型"); if (tempValue.isObject()) { tempObject = tempValue.toObject(); } else { qDebug() << "电源盒类型 error" << tempValue.type() ; return; } tempValue = tempObject.value("类型"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "类型 error" << tempValue.type() ; return; } tempString.remove("H"); // 将字符串转换为整数(基数为 16) tempU16 = tempString.toInt(&ok, 16); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; tempValue = rootObj.value("电源盒类型"); tempValue = tempObject.value("power_Box_Type"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "power_Box_Type error" << tempValue.type() ; return; } tempString.remove("0x"); *writeCfgPoint = tempString.toInt(&ok, 16); writeCfgPoint += 1; dataLen += 1; /* 恒压充电阈值电压 */ tempValue = rootObj.value("恒压充电阈值电压"); if (tempValue.isObject()) { tempObject = tempValue.toObject(); } else { qDebug() << "恒压充电阈值电压 error" << tempValue.type() ; return; } tempValue = tempObject.value("类型"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "类型 error" << tempValue.type() ; return; } tempString.remove("H"); // 将字符串转换为整数(基数为 16) tempU16 = tempString.toInt(&ok, 16); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; tempValue = rootObj.value("恒压充电阈值电压"); tempValue = tempObject.value("constant_Voltage_V"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "constant_Voltage_V error" << tempValue.type() ; return; } float tempFloat = tempString.toFloat(&ok); if (!ok) { qDebug() << "转换失败!"; return; } tempU16 = tempFloat * 10; *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; /* 浮充充电阈值电流 */ tempValue = rootObj.value("浮充充电阈值电流"); if (tempValue.isObject()) { tempObject = tempValue.toObject(); } else { qDebug() << "浮充充电阈值电流 error" << tempValue.type() ; return; } tempValue = tempObject.value("类型"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "类型 error" << tempValue.type() ; return; } tempString.remove("H"); // 将字符串转换为整数(基数为 16) tempU16 = tempString.toInt(&ok, 16); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; tempValue = rootObj.value("浮充充电阈值电流"); tempValue = tempObject.value("float_I"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "float_I error" << tempValue.type() ; return; } tempFloat = tempString.toFloat(&ok); if (!ok) { qDebug() << "转换失败!"; return; } tempU16 = tempFloat * 10; *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; /* 启动充电太阳能板开路电压 */ tempValue = rootObj.value("启动充电太阳能板开路电压"); if (tempValue.isObject()) { tempObject = tempValue.toObject(); } else { qDebug() << "启动充电太阳能板开路电压 error" << tempValue.type() ; return; } tempValue = tempObject.value("类型"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "类型 error" << tempValue.type() ; return; } tempString.remove("H"); // 将字符串转换为整数(基数为 16) tempU16 = tempString.toInt(&ok, 16); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; tempValue = rootObj.value("启动充电太阳能板开路电压"); tempValue = tempObject.value("start_Solar_Open_Circuit_V"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "start_Solar_Open_Circuit_V error" << tempValue.type() ; return; } tempFloat = tempString.toFloat(&ok); if (!ok) { qDebug() << "转换失败!"; return; } tempU16 = tempFloat * 10; *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; /* 停止充电太阳能板输出电压 */ tempValue = rootObj.value("停止充电太阳能板输出电压"); if (tempValue.isObject()) { tempObject = tempValue.toObject(); } else { qDebug() << "停止充电太阳能板输出电压 error" << tempValue.type() ; return; } tempValue = tempObject.value("类型"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "类型 error" << tempValue.type() ; return; } tempString.remove("H"); // 将字符串转换为整数(基数为 16) tempU16 = tempString.toInt(&ok, 16); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; tempValue = rootObj.value("停止充电太阳能板输出电压"); tempValue = tempObject.value("stop_Solar_Output_Circuit_V"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "stop_Solar_Output_Circuit_V error" << tempValue.type() ; return; } tempFloat = tempString.toFloat(&ok); if (!ok) { qDebug() << "转换失败!"; return; } tempU16 = tempFloat * 10; *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; /* 启动时开路电压检测间隔 */ tempValue = rootObj.value("启动时开路电压检测间隔"); if (tempValue.isObject()) { tempObject = tempValue.toObject(); } else { qDebug() << "启动时开路电压检测间隔 error" << tempValue.type() ; return; } tempValue = tempObject.value("类型"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "类型 error" << tempValue.type() ; return; } tempString.remove("H"); // 将字符串转换为整数(基数为 16) tempU16 = tempString.toInt(&ok, 16); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; tempValue = rootObj.value("启动时开路电压检测间隔"); tempValue = tempObject.value("check_Can_Start_Time"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "check_Can_Start_Time error" << tempValue.type() ; return; } tempU16 = tempString.toInt(&ok); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; /* 短路判断延时 */ tempValue = rootObj.value("短路判断延时"); if (tempValue.isObject()) { tempObject = tempValue.toObject(); } else { qDebug() << "短路判断延时 error" << tempValue.type() ; return; } tempValue = tempObject.value("类型"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "类型 error" << tempValue.type() ; return; } tempString.remove("H"); // 将字符串转换为整数(基数为 16) tempU16 = tempString.toInt(&ok, 16); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; tempValue = rootObj.value("短路判断延时"); tempValue = tempObject.value("short_Circuit_Judgment_Delay"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "short_Circuit_Judgment_Delay error" << tempValue.type() ; return; } tempU16 = tempString.toInt(&ok); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; /* 前端输入功率不足判断延时 */ tempValue = rootObj.value("前端输入功率不足判断延时"); if (tempValue.isObject()) { tempObject = tempValue.toObject(); } else { qDebug() << "前端输入功率不足判断延时 error" << tempValue.type() ; return; } tempValue = tempObject.value("类型"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "类型 error" << tempValue.type() ; return; } tempString.remove("H"); // 将字符串转换为整数(基数为 16) tempU16 = tempString.toInt(&ok, 16); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; tempValue = rootObj.value("前端输入功率不足判断延时"); tempValue = tempObject.value("input_Power_Low_Judgment_Delay"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "input_Power_Low_Judgment_Delay error" << tempValue.type() ; return; } tempU16 = tempString.toInt(&ok); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; /* 前端输入功率不足后再次输出延时 */ tempValue = rootObj.value("前端输入功率不足后再次输出延时"); if (tempValue.isObject()) { tempObject = tempValue.toObject(); } else { qDebug() << "前端输入功率不足后再次输出延时 error" << tempValue.type() ; return; } tempValue = tempObject.value("类型"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "类型 error" << tempValue.type() ; return; } tempString.remove("H"); // 将字符串转换为整数(基数为 16) tempU16 = tempString.toInt(&ok, 16); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; tempValue = rootObj.value("前端输入功率不足后再次输出延时"); tempValue = tempObject.value("input_Power_Low_Again_Output_Delay"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "input_Power_Low_Again_Output_Delay error" << tempValue.type() ; return; } tempU16 = tempString.toInt(&ok); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; /* 第一段保护延时 */ tempValue = rootObj.value("第一段保护延时"); if (tempValue.isObject()) { tempObject = tempValue.toObject(); } else { qDebug() << "第一段保护延时 error" << tempValue.type() ; return; } tempValue = tempObject.value("类型"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "类型 error" << tempValue.type() ; return; } tempString.remove("H"); // 将字符串转换为整数(基数为 16) tempU16 = tempString.toInt(&ok, 16); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; tempValue = rootObj.value("第一段保护延时"); tempValue = tempObject.value("first_Stage_Protection_Delay"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "first_Stage_Protection_Delay error" << tempValue.type() ; return; } tempU16 = tempString.toInt(&ok); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; /* 第一段保护的电流 */ tempValue = rootObj.value("第一段保护的电流"); if (tempValue.isObject()) { tempObject = tempValue.toObject(); } else { qDebug() << "第一段保护的电流 error" << tempValue.type() ; return; } tempValue = tempObject.value("类型"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "类型 error" << tempValue.type() ; return; } tempString.remove("H"); // 将字符串转换为整数(基数为 16) tempU16 = tempString.toInt(&ok, 16); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; tempValue = rootObj.value("第一段保护的电流"); tempValue = tempObject.value("first_Stage_Protection_Curr"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "first_Stage_Protection_Curr error" << tempValue.type() ; return; } tempFloat = tempString.toFloat(&ok); if (!ok) { qDebug() << "转换失败!"; return; } tempU16 = tempFloat * 10; *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; /* 第二段保护延时 */ tempValue = rootObj.value("第二段保护延时"); if (tempValue.isObject()) { tempObject = tempValue.toObject(); } else { qDebug() << "第二段保护延时 error" << tempValue.type() ; return; } tempValue = tempObject.value("类型"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "类型 error" << tempValue.type() ; return; } tempString.remove("H"); // 将字符串转换为整数(基数为 16) tempU16 = tempString.toInt(&ok, 16); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; tempValue = rootObj.value("第二段保护延时"); tempValue = tempObject.value("second_Stage_Protection_Delay"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "second_Stage_Protection_Delay error" << tempValue.type() ; return; } tempU16 = tempString.toInt(&ok); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; /* 第二段保护的电流 */ tempValue = rootObj.value("第二段保护的电流"); if (tempValue.isObject()) { tempObject = tempValue.toObject(); } else { qDebug() << "第二段保护的电流 error" << tempValue.type() ; return; } tempValue = tempObject.value("类型"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "类型 error" << tempValue.type() ; return; } tempString.remove("H"); // 将字符串转换为整数(基数为 16) tempU16 = tempString.toInt(&ok, 16); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; tempValue = rootObj.value("第二段保护的电流"); tempValue = tempObject.value("second_Stage_Protection_Curr"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "second_Stage_Protection_Curr error" << tempValue.type() ; return; } tempFloat = tempString.toFloat(&ok); if (!ok) { qDebug() << "转换失败!"; return; } tempU16 = tempFloat * 10; *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; /* 第三段保护延时 */ tempValue = rootObj.value("第三段保护延时"); if (tempValue.isObject()) { tempObject = tempValue.toObject(); } else { qDebug() << "第三段保护延时 error" << tempValue.type() ; return; } tempValue = tempObject.value("类型"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "类型 error" << tempValue.type() ; return; } tempString.remove("H"); // 将字符串转换为整数(基数为 16) tempU16 = tempString.toInt(&ok, 16); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; tempValue = rootObj.value("第三段保护延时"); tempValue = tempObject.value("third_Stage_Protection_Delay"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "third_Stage_Protection_Delay error" << tempValue.type() ; return; } uint32_t tempU32 = tempString.toInt(&ok); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU32 >> 24); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)(tempU32 >> 16); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)(tempU32 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU32; writeCfgPoint += 1; dataLen += 4; /* 第三段保护的电流 */ tempValue = rootObj.value("第三段保护的电流"); if (tempValue.isObject()) { tempObject = tempValue.toObject(); } else { qDebug() << "第三段保护的电流 error" << tempValue.type() ; return; } tempValue = tempObject.value("类型"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "类型 error" << tempValue.type() ; return; } tempString.remove("H"); // 将字符串转换为整数(基数为 16) tempU16 = tempString.toInt(&ok, 16); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; tempValue = rootObj.value("第三段保护的电流"); tempValue = tempObject.value("third_Stage_Protection_Curr"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "third_Stage_Protection_Curr error" << tempValue.type() ; return; } tempFloat = tempString.toFloat(&ok); if (!ok) { qDebug() << "转换失败!"; return; } tempU16 = tempFloat * 10; *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; /* 前端输入功率不足检测延时 */ tempValue = rootObj.value("前端输入功率不足检测延时"); if (tempValue.isObject()) { tempObject = tempValue.toObject(); } else { qDebug() << "前端输入功率不足检测延时 error" << tempValue.type() ; return; } tempValue = tempObject.value("类型"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "类型 error" << tempValue.type() ; return; } tempString.remove("H"); // 将字符串转换为整数(基数为 16) tempU16 = tempString.toInt(&ok, 16); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; tempValue = rootObj.value("前端输入功率不足检测延时"); tempValue = tempObject.value("input_Power_Low_Detection_Delay"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "input_Power_Low_Detection_Delay error" << tempValue.type() ; return; } tempU16 = tempString.toInt(&ok); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; /* 前端输入功率不足检测电压 */ tempValue = rootObj.value("前端输入功率不足检测电压"); if (tempValue.isObject()) { tempObject = tempValue.toObject(); } else { qDebug() << "前端输入功率不足检测电压 error" << tempValue.type() ; return; } tempValue = tempObject.value("类型"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "类型 error" << tempValue.type() ; return; } tempString.remove("H"); // 将字符串转换为整数(基数为 16) tempU16 = tempString.toInt(&ok, 16); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; tempValue = rootObj.value("前端输入功率不足检测电压"); tempValue = tempObject.value("input_Power_Low_Detection_Volt"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "input_Power_Low_Detection_Volt error" << tempValue.type() ; return; } tempFloat = tempString.toFloat(&ok); if (!ok) { qDebug() << "转换失败!"; return; } tempU16 = tempFloat * 10; *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; /* 最大太阳能板输出电压 */ tempValue = rootObj.value("最大太阳能板输出电压"); if (tempValue.isObject()) { tempObject = tempValue.toObject(); } else { qDebug() << "最大太阳能板输出电压 error" << tempValue.type() ; return; } tempValue = tempObject.value("类型"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "类型 error" << tempValue.type() ; return; } tempString.remove("H"); // 将字符串转换为整数(基数为 16) tempU16 = tempString.toInt(&ok, 16); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; tempValue = rootObj.value("最大太阳能板输出电压"); tempValue = tempObject.value("max_Open_Solar_Output_Circuit_V"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "max_Open_Solar_Output_Circuit_V error" << tempValue.type() ; return; } tempFloat = tempString.toFloat(&ok); if (!ok) { qDebug() << "转换失败!"; return; } tempU16 = tempFloat * 10; *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; /* 最大充电电流 */ tempValue = rootObj.value("最大充电电流"); if (tempValue.isObject()) { tempObject = tempValue.toObject(); } else { qDebug() << "最大充电电流 error" << tempValue.type() ; return; } tempValue = tempObject.value("类型"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "类型 error" << tempValue.type() ; return; } tempString.remove("H"); // 将字符串转换为整数(基数为 16) tempU16 = tempString.toInt(&ok, 16); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; tempValue = rootObj.value("最大充电电流"); tempValue = tempObject.value("max_Charg_Curr"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "max_Charg_Curr error" << tempValue.type() ; return; } tempFloat = tempString.toFloat(&ok); if (!ok) { qDebug() << "转换失败!"; return; } tempU16 = tempFloat * 10; *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; /* 检测回路阻抗时的最小充电电流 */ tempValue = rootObj.value("检测回路阻抗时的最小充电电流"); if (tempValue.isObject()) { tempObject = tempValue.toObject(); } else { qDebug() << "检测回路阻抗时的最小充电电流 error" << tempValue.type() ; return; } tempValue = tempObject.value("类型"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "类型 error" << tempValue.type() ; return; } tempString.remove("H"); // 将字符串转换为整数(基数为 16) tempU16 = tempString.toInt(&ok, 16); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; tempValue = rootObj.value("检测回路阻抗时的最小充电电流"); tempValue = tempObject.value("min_Check_Loop_Impedance_Charg_Curr"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "min_Check_Loop_Impedance_Charg_Curr error" << tempValue.type() ; return; } tempFloat = tempString.toFloat(&ok); if (!ok) { qDebug() << "转换失败!"; return; } tempU16 = tempFloat * 10; *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; /* 全功率输出温度 */ tempValue = rootObj.value("全功率输出温度"); if (tempValue.isObject()) { tempObject = tempValue.toObject(); } else { qDebug() << "全功率输出温度 error" << tempValue.type() ; return; } tempValue = tempObject.value("类型"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "类型 error" << tempValue.type() ; return; } tempString.remove("H"); // 将字符串转换为整数(基数为 16) tempU16 = tempString.toInt(&ok, 16); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; tempValue = rootObj.value("全功率输出温度"); tempValue = tempObject.value("full_Power_Output_Temperature"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "full_Power_Output_Temperature error" << tempValue.type() ; return; } tempFloat = tempString.toFloat(&ok); if (!ok) { qDebug() << "转换失败!"; return; } tempU16 = tempFloat * 10; *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; /* 降功率输出温度 */ tempValue = rootObj.value("降功率输出温度"); if (tempValue.isObject()) { tempObject = tempValue.toObject(); } else { qDebug() << "降功率输出温度 error" << tempValue.type() ; return; } tempValue = tempObject.value("类型"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "类型 error" << tempValue.type() ; return; } tempString.remove("H"); // 将字符串转换为整数(基数为 16) tempU16 = tempString.toInt(&ok, 16); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; tempValue = rootObj.value("降功率输出温度"); tempValue = tempObject.value("reduce_Power_Output_Temperature"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "reduce_Power_Output_Temperature error" << tempValue.type() ; return; } tempFloat = tempString.toFloat(&ok); if (!ok) { qDebug() << "转换失败!"; return; } tempU16 = tempFloat * 10; *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; /* 停止输出温度 */ tempValue = rootObj.value("停止输出温度"); if (tempValue.isObject()) { tempObject = tempValue.toObject(); } else { qDebug() << "停止输出温度 error" << tempValue.type() ; return; } tempValue = tempObject.value("类型"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "类型 error" << tempValue.type() ; return; } tempString.remove("H"); // 将字符串转换为整数(基数为 16) tempU16 = tempString.toInt(&ok, 16); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; tempValue = rootObj.value("停止输出温度"); tempValue = tempObject.value("stop_PowerOutput_Temperature"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "stop_PowerOutput_Temperature error" << tempValue.type() ; return; } tempFloat = tempString.toFloat(&ok); if (!ok) { qDebug() << "转换失败!"; return; } tempU16 = tempFloat * 10; *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; /* 恒压充电时的输出电压 */ tempValue = rootObj.value("恒压充电时的输出电压"); if (tempValue.isObject()) { tempObject = tempValue.toObject(); } else { qDebug() << "恒压充电时的输出电压 error" << tempValue.type() ; return; } tempValue = tempObject.value("类型"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "类型 error" << tempValue.type() ; return; } tempString.remove("H"); // 将字符串转换为整数(基数为 16) tempU16 = tempString.toInt(&ok, 16); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; tempValue = rootObj.value("恒压充电时的输出电压"); tempValue = tempObject.value("constant_Voltage_Charge_V"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "constant_Voltage_Charge_V error" << tempValue.type() ; return; } tempFloat = tempString.toFloat(&ok); if (!ok) { qDebug() << "转换失败!"; return; } tempU16 = tempFloat * 10; *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; /* 浮充充电时的输出电压 */ tempValue = rootObj.value("浮充充电时的输出电压"); if (tempValue.isObject()) { tempObject = tempValue.toObject(); } else { qDebug() << "浮充充电时的输出电压 error" << tempValue.type() ; return; } tempValue = tempObject.value("类型"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "类型 error" << tempValue.type() ; return; } tempString.remove("H"); // 将字符串转换为整数(基数为 16) tempU16 = tempString.toInt(&ok, 16); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; tempValue = rootObj.value("浮充充电时的输出电压"); tempValue = tempObject.value("float_ChargeV"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "float_ChargeV error" << tempValue.type() ; return; } tempFloat = tempString.toFloat(&ok); if (!ok) { qDebug() << "转换失败!"; return; } tempU16 = tempFloat * 10; *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; /* 充电时开路电压采集间隔 */ tempValue = rootObj.value("充电时开路电压采集间隔"); if (tempValue.isObject()) { tempObject = tempValue.toObject(); } else { qDebug() << "充电时开路电压采集间隔 error" << tempValue.type() ; return; } tempValue = tempObject.value("类型"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "类型 error" << tempValue.type() ; return; } tempString.remove("H"); // 将字符串转换为整数(基数为 16) tempU16 = tempString.toInt(&ok, 16); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; tempValue = rootObj.value("充电时开路电压采集间隔"); tempValue = tempObject.value("collect_OpenCircuit_Voltage_Time"); if (tempValue.isString()) { tempString = tempValue.toString(); } else { qDebug() << "collect_OpenCircuit_Voltage_Time error" << tempValue.type() ; return; } tempU16 = tempString.toInt(&ok); if (!ok) { qDebug() << "转换失败!"; return; } *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; dataLen += 2; /* 数据长度 */ writeCfgBuf[12] = (uint8_t)(dataLen >> 8); writeCfgBuf[13] = (uint8_t)dataLen; /* modbusCrc校验 */ tempU16 = modbusCrc(writeCfgBuf, dataLen + 14); *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; writeCfgPoint += 1; *writeCfgPoint = 0x16; // for (int i = 0; i < dataLen + 17; i++) { // qDebug(" 0x%x ", writeCfgBuf[i]); // } serialPort->write(reinterpret_cast(writeCfgBuf), (dataLen + 17)); }