From 1ede325a3ef0ed5f14195dfd7bfddf1bdaa1d40f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B7=E5=BA=8A=E5=B0=B1=E7=8A=AF=E5=9B=B0?= <11730503+psx123456@user.noreply.gitee.com> Date: Tue, 21 Jan 2025 18:01:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=8B=E5=8F=91=E8=A7=A3?= =?UTF-8?q?=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mainwindow.cpp | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index ad615a2..f42bf7d 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -393,9 +393,9 @@ void MainWindow::readCfgFile() readCfgPoint += 1; /* 数据长度 */ - *readCfgPoint = 29 >> 8; + *readCfgPoint = 60 >> 8; readCfgPoint += 1; - *readCfgPoint = 29; + *readCfgPoint = 60; readCfgPoint += 1; /* 数据内容 */ @@ -544,9 +544,14 @@ void MainWindow::readCfgFile() *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, (29 * 2 + 12)); + tempU16 = modbusCrc(readCfgBuf, (60 + 12)); *readCfgPoint = (uint8_t)(tempU16 >> 8); readCfgPoint += 1; *readCfgPoint = (uint8_t)tempU16; @@ -642,28 +647,41 @@ void MainWindow::readCfgFile() // } // readCfgBuf[10]++; - ui->SerialPortPushButton->setEnabled(false); - ui->readConfigFile->setEnabled(false); - ui->writeConfigFile->setEnabled(false); + ui->SerialPortPushButton->setDisabled(true); + ui->readConfigFile->setDisabled(true); + ui->writeConfigFile->setDisabled(true); - serialPort->write(reinterpret_cast(readCfgBuf), (29 * 2 + 12 + 3)); + serialPort->write(reinterpret_cast(readCfgBuf), (60 + 12 + 3)); -// /* 延时1.5S */ -// QThread::msleep(1500); -// QByteArray data = serialPort->readAll(); + /* 延时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 (data.at(0) != 'S' || data.at(1) != 'L') { -// goto error; -// } + if (*(repData + 9) != 0xD0) { + goto error; + } + +// uint16_t crc16 = modbusCrc(repData, 14); +// return; -//error: +error: ui->SerialPortPushButton->setEnabled(true); ui->readConfigFile->setEnabled(true); ui->writeConfigFile->setEnabled(true);