浏览代码

封装了读取保存历史通信记录代码

master
鹏鹏 李 1周前
父节点
当前提交
059854d8fc
共有 10 个文件被更改,包括 607 次插入545 次删除
  1. +54
    -0
      communicationhistory.cpp
  2. +17
    -0
      communicationhistory.h
  3. +2
    -1
      crc.h
  4. +4
    -2
      modbus.pro
  5. +1
    -1
      modbus.pro.user
  6. +51
    -51
      mymodbus.cpp
  7. +8
    -8
      mymodbus.h
  8. +59
    -112
      widget.cpp
  9. +5
    -3
      widget.h
  10. +406
    -367
      widget.ui

+ 54
- 0
communicationhistory.cpp 查看文件

@@ -0,0 +1,54 @@
#include "communicationhistory.h"

bool SaveDate(QWidget *parent, QTextEdit *edit)
{
QString fileName = QFileDialog::getSaveFileName(
parent,
"保存文本",
QDir::homePath() + "/note.txt",
"文本文件 (*.txt);;所有文件 (*)");

if (fileName.isEmpty())
return false;

QFile file(fileName);
if (!file.open(QIODevice::Append | QIODevice::Text))
{
QMessageBox::warning(parent, "错误", "无法打开文件");
return false;
}

if (file.size() > 0)
file.write("\n");

QTextStream out(&file);
out.setCodec("UTF-8");
out << edit->toPlainText();
file.close();
return true;
}

bool ReadDate(QWidget *parent, QTextEdit *edit)
{
QString fileName = QFileDialog::getOpenFileName(
parent,
"打开文本",
QDir::homePath(),
"文本文件 (*.txt);;所有文件 (*)");

if (fileName.isEmpty())
return false;

QFile file(fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
QMessageBox::warning(parent, "错误", "无法读取文件");
return false;
}

QTextStream in(&file);
in.setCodec("UTF-8");
edit->setPlainText(in.readAll());
file.close();
return true;
}

+ 17
- 0
communicationhistory.h 查看文件

@@ -0,0 +1,17 @@
#ifndef COMMUNICATIONHISTORY_H
#define COMMUNICATIONHISTORY_H

#pragma once
#include <QString>
#include <QFileDialog>
#include <QMessageBox>
#include <QFile>
#include <QTextStream>
#include <QDir>
#include <QTextEdit>

bool SaveDate(QWidget *parent, QTextEdit *edit);

bool ReadDate(QWidget *parent, QTextEdit *edit);

#endif // COMMUNICATIONHISTORY_H

+ 2
- 1
crc.h 查看文件

@@ -1,9 +1,10 @@
#ifndef CRC_H
#define CRC_H

#endif // CRC_H
#include <QByteArray>
#include <QtGlobal>

quint16 CalculateCrc(const QByteArray &data);
bool CrcCheck(const QByteArray &data);

#endif // CRC_H

+ 4
- 2
modbus.pro 查看文件

@@ -16,10 +16,12 @@ TEMPLATE = app
SOURCES += main.cpp\
widget.cpp \
crc.cpp \
mymodbus.cpp
mymodbus.cpp \
communicationhistory.cpp

HEADERS += widget.h \
crc.h \
mymodbus.h
mymodbus.h \
communicationhistory.h

FORMS += widget.ui

+ 1
- 1
modbus.pro.user 查看文件

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.0.3, 2025-07-26T17:06:45. -->
<!-- Written by QtCreator 4.0.3, 2025-07-28T10:59:33. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>


+ 51
- 51
mymodbus.cpp 查看文件

@@ -7,25 +7,25 @@ MyModbus::MyModbus()

void MyModbus::Set(quint16 stationAddress, quint16 functionCode, quint16 startAdress, quint16 length)
{
this->stationAddress = stationAddress;
this->functionCode = functionCode;
this->startAdress = startAdress;
this->length = length;
this->stationAddress_ = stationAddress;
this->functionCode_ = functionCode;
this->startAdress_ = startAdress;
this->length_ = length;

}

void MyModbus::ReadColiAndReg()
void MyModbus::ReadCoilAndReg()
{
sendCommand.clear();
sendCommand.append(stationAddress%256);
sendCommand.append(functionCode%256);
sendCommand.append(startAdress/256);
sendCommand.append(startAdress%256);
sendCommand.append(length/256);
sendCommand.append(length%256);
quint16 temp = CalculateCrc(sendCommand);
sendCommand.append(temp%256);
sendCommand.append(temp/256);
sendCommand_.clear();
sendCommand_.append(stationAddress_%256);
sendCommand_.append(functionCode_%256);
sendCommand_.append(startAdress_/256);
sendCommand_.append(startAdress_%256);
sendCommand_.append(length_/256);
sendCommand_.append(length_%256);
quint16 temp = CalculateCrc(sendCommand_);
sendCommand_.append(temp%256);
sendCommand_.append(temp/256);
}

void MyModbus::WriteCoil(QVector<bool> &coils)
@@ -33,14 +33,14 @@ void MyModbus::WriteCoil(QVector<bool> &coils)
quint16 coilCount = coils.size();
int byteCount = (coilCount + 7) / 8;

sendCommand.clear();
sendCommand.append(stationAddress%256);
sendCommand.append(0x0f);
sendCommand.append(startAdress/256);
sendCommand.append(startAdress%256);
sendCommand.append(length/256);
sendCommand.append(length%256);
sendCommand.append(byteCount);
sendCommand_.clear();
sendCommand_.append(stationAddress_%256);
sendCommand_.append(0x0f);
sendCommand_.append(startAdress_/256);
sendCommand_.append(startAdress_%256);
sendCommand_.append(length_/256);
sendCommand_.append(length_%256);
sendCommand_.append(byteCount);
for (int i = 0; i < byteCount; ++i)
{
quint8 byte = 0;
@@ -50,55 +50,55 @@ void MyModbus::WriteCoil(QVector<bool> &coils)
if (bitIndex < coils.size() && coils[bitIndex])
byte |= (1 << j);
}
sendCommand.append(static_cast<char>(byte));
sendCommand_.append(static_cast<char>(byte));
}

quint16 temp = CalculateCrc(sendCommand); //计算crc
sendCommand.append(temp%256); //加入计算的crc值
sendCommand.append(temp/256);
quint16 temp = CalculateCrc(sendCommand_); //计算crc
sendCommand_.append(temp%256); //加入计算的crc值
sendCommand_.append(temp/256);
}

void MyModbus::WriteRegister(QVector<quint16> &values)
{
sendCommand.clear();
sendCommand.append(stationAddress%256);
sendCommand.append(0x10);
sendCommand.append(startAdress/256);
sendCommand.append(startAdress%256);
sendCommand.append(length/256);
sendCommand.append(length%256);
sendCommand.append(static_cast<char>(values.size() * 2));
sendCommand_.clear();
sendCommand_.append(stationAddress_%256);
sendCommand_.append(0x10);
sendCommand_.append(startAdress_/256);
sendCommand_.append(startAdress_%256);
sendCommand_.append(length_/256);
sendCommand_.append(length_%256);
sendCommand_.append(static_cast<char>(values.size() * 2));
for (quint16 v : values)
{
sendCommand.append(static_cast<char>((v >> 8) & 0xFF));
sendCommand.append(static_cast<char>(v & 0xFF));
sendCommand_.append(static_cast<char>((v >> 8) & 0xFF));
sendCommand_.append(static_cast<char>(v & 0xFF));
}
quint16 temp = CalculateCrc(sendCommand); //计算crc
sendCommand.append(temp%256); //加入计算的crc值
sendCommand.append(temp/256);
quint16 temp = CalculateCrc(sendCommand_); //计算crc
sendCommand_.append(temp%256); //加入计算的crc值
sendCommand_.append(temp/256);
}

QByteArray MyModbus::SendCommand()
{
return sendCommand;
return sendCommand_;
}

QByteArray MyModbus::Receive(const QByteArray &revMessage)
{
receive.clear();
receive_.clear();
if (CrcCheck(revMessage))
{
this->receive = revMessage;
this->receive_ = revMessage;
}
return receive;
return receive_;
}

int MyModbus::ErrorCheck()
{
if ((receive.at(1) & 0x80) == 0x80)
if ((receive_.at(1) & 0x80) == 0x80)
{
// MODBUS异常响应结构:地址 | 功能码+0x80 | 异常码 | CRC
quint8 exCode = receive.at(2);
quint8 exCode = receive_.at(2);
return exCode;
}
else
@@ -109,18 +109,18 @@ int MyModbus::ErrorCheck()

QVector<bool> MyModbus::AnalReadCoil()
{
quint8 byteCount = static_cast<quint8>(receive[2]);
quint8 byteCount = static_cast<quint8>(receive_[2]);
QVector<bool> coil;

for (int byteIndex = 0; byteIndex < byteCount; byteIndex++)
{
quint8 byteValue = static_cast<quint8>(receive[3 + byteIndex]);
quint8 byteValue = static_cast<quint8>(receive_[3 + byteIndex]);

// 解析每个字节的8个位
for (int bitIndex = 0; bitIndex < 8; bitIndex++)
{
int coilIndex = byteIndex * 8 + bitIndex;
if (coilIndex < length)
if (coilIndex < length_)
{
bool state = byteValue & (1 << bitIndex);
coil.append(state);
@@ -132,8 +132,8 @@ QVector<bool> MyModbus::AnalReadCoil()

QVector<quint16> MyModbus::AnalReadReg()
{
int byteCount = receive.at(2);
QByteArray data = receive.mid(3, byteCount);
int byteCount = receive_.at(2);
QByteArray data = receive_.mid(3, byteCount);

QVector<quint16> registers;
for (int i = 0; i < data.size(); i += 2)


+ 8
- 8
mymodbus.h 查看文件

@@ -9,17 +9,17 @@
class MyModbus
{
private:
quint16 stationAddress;
quint16 functionCode;
quint16 startAdress;
quint16 length;
QByteArray sendCommand;
QByteArray receive;
quint16 stationAddress_;
quint16 functionCode_;
quint16 startAdress_;
quint16 length_;
QByteArray sendCommand_;
QByteArray receive_;

public:
MyModbus();
void Set(quint16 stationAddress,quint16 functionCode,quint16 startAdress,quint16 length);
void ReadColiAndReg();
void Set(quint16 stationAddress_,quint16 functionCode_,quint16 startAdress_,quint16 length_);
void ReadCoilAndReg();
void WriteCoil(QVector<bool> &coils);
void WriteRegister(QVector<quint16> &values);
QByteArray SendCommand();


+ 59
- 112
widget.cpp 查看文件

@@ -8,10 +8,9 @@
#include <QVector>
#include <QMessageBox>
#include <synchapi.h>
#include <QFile>
#include <QFileDialog>
#include "crc.h"
#include "mymodbus.h"
#include "communicationhistory.h"

Widget::Widget(QWidget *parent) :
QWidget(parent),
@@ -30,18 +29,14 @@ Widget::Widget(QWidget *parent) :
ui->textEdit_2->append("通信超时,重新发送中");

serialPort->write(modbus->SendCommand());
Sleep(1000);
timer.isActive();
timer.start(1000);

comCount ++;
}
else
{
QMessageBox::warning(this, "提示", "等待响应超时,请检查设备状态。");
ui->btn_read->setEnabled(1);
ui->pushWrite->setEnabled(1);
timer.stop();
QMessageBox::warning(this, "提示", "等待响应超时,请检查设备状态。");
ui->btn_read->setEnabled(1);
ui->pushWrite->setEnabled(1);
timer.stop();
}
});

@@ -61,6 +56,7 @@ Widget::Widget(QWidget *parent) :

Widget::~Widget()
{
delete modbus;
delete ui;
}

@@ -69,13 +65,13 @@ void Widget::on_btnConnect_clicked()
{
if (ui->btnConnect->text() == "连接")
{
//配置串口号
//配置串口号
serialPort->setPortName(ui->comboBox_serialNum->currentText());
//配置波特率
//配置波特率
serialPort->setBaudRate(ui->comboBox_baudRate->currentText().toInt());
//配置数据位
//配置数据位
serialPort->setDataBits(QSerialPort::DataBits(ui->comboBox_dataBit->currentText().toInt()));
//配置校验位
//配置校验位
switch (ui->comboBox_xiaoyan->currentIndex())
{
case 0:
@@ -87,12 +83,11 @@ void Widget::on_btnConnect_clicked()
case 2:
serialPort->setParity(QSerialPort::EvenParity);
}
//配置停止位
//配置停止位
serialPort->setStopBits(QSerialPort::StopBits(ui->comboBox_stopBit->currentText().toInt()));
//打开串口
//打开串口
if (serialPort->open(QIODevice::ReadWrite))
{
qDebug() << "Serial open success";
ui->textEdit_2->append("串口连接成功");
ui->btnConnect->setText("断开");
ui->btn_read->setEnabled(1);
@@ -100,13 +95,11 @@ void Widget::on_btnConnect_clicked()
}
else
{
qDebug() << "error";
QMessageBox::warning(this, "提示", "串口连接失败,请检查串口参数配置");
}
}
else
{
delete modbus;
serialPort->close();
ui->btn_read->setEnabled(0);
ui->pushWrite->setEnabled(0);
@@ -124,44 +117,42 @@ void Widget::on_pushWrite_clicked()
{
case 2: //写多个线圈
{
QString sendData = ui->lineEdit->text().trimmed();
if (sendData.isEmpty())
{
QMessageBox::warning(this, "提示", "请至少输入一个数据,缺少的数据默认为0");
return;
}
for (QChar ch : sendData) {
if (ch != '0' && ch != '1') {
QMessageBox::warning(this, "提示", "只允许输入 0 或 1!");
QString sendData = ui->lineEdit->text().trimmed();
if (sendData.isEmpty())
{
QMessageBox::warning(this, "提示", "请至少输入一个数据,缺少的数据默认为0");
return;
}
}
for (QChar ch : sendData) {
if (ch != '0' && ch != '1') {
QMessageBox::warning(this, "提示", "只允许输入 0 或 1!");
return;
}
}

QVector<bool> coils;
for (QChar ch : sendData)
{
coils.append(ch == '1');
}
QVector<bool> coils;
for (QChar ch : sendData)
{
coils.append(ch == '1');
}

quint16 stationAddress = ui->comboBox_stationAddress->currentText().toInt();
quint16 functionCode = 0x0f;
quint16 stratAddress = ui->lineEdit_stratAddress->text().toInt();
quint16 length = ui->lineEdit_length->text().toInt();
quint16 stationAddress = ui->comboBox_stationAddress->currentText().toInt();
quint16 functionCode = 0x0f;
quint16 stratAddress = ui->lineEdit_stratAddress->text().toInt();
quint16 length = ui->lineEdit_length->text().toInt();

modbus->Set(stationAddress,functionCode,stratAddress,length);
modbus->WriteCoil(coils);
modbus->Set(stationAddress,functionCode,stratAddress,length);
modbus->WriteCoil(coils);

ui->textEdit_2->append("发送报文"+modbus->SendCommand().toHex().toUpper());
serialPort->write(modbus->SendCommand());
ui->btn_read->setEnabled(0);
ui->pushWrite->setEnabled(0);
ui->textEdit_2->append("发送报文"+modbus->SendCommand().toHex().toUpper());
serialPort->write(modbus->SendCommand());
ui->btn_read->setEnabled(0);
ui->pushWrite->setEnabled(0);

comCount = 0;
Sleep(100);
timer.isActive();
timer.start(1000); // 1 s 后触发超时
comCount = 0;
timer.start(1000); // 1 s 后触发超时

break;
break;
}

case 3:
@@ -188,7 +179,7 @@ void Widget::on_pushWrite_clicked()
}

quint16 stationAddress = ui->comboBox_stationAddress->currentText().toInt();
quint16 functionCode = 0x0f;
quint16 functionCode = 0x10;
quint16 stratAddress = ui->lineEdit_stratAddress->text().toInt();
quint16 length = ui->lineEdit_length->text().toInt();

@@ -201,11 +192,8 @@ void Widget::on_pushWrite_clicked()
ui->pushWrite->setEnabled(0);

comCount = 0;
Sleep(100);
timer.isActive();
timer.start(1000); // 1 s 后触发超时

qDebug() << "SenOk" <<sendData;
break;
}
default:
@@ -234,10 +222,8 @@ void Widget::on_SerialData_ReadyToRead()
return;
}
QString hexData = revMessage.toHex().toUpper();
qDebug() << hexData;
ui->textEdit_2->append("接收报文"+hexData);

qDebug() << "接收成功";
int exCode = modbus->ErrorCheck();
if (exCode)
{
@@ -278,13 +264,14 @@ void Widget::on_SerialData_ReadyToRead()
//解析读寄存器的返回报文
case 1:
{
QVector<quint16> registers = modbus->AnalReadReg();
QVector<quint16> registers = modbus->AnalReadReg();

ui->textEdit->append("寄存器的值:");
for (int i = 0; i < registers.size(); i++)
{
ui->textEdit->append("寄存器"+QString::number(i+1)+":"+QString::number(registers.at(i)));
}

ui->textEdit->append("寄存器的值:");
for (int i = 0; i < registers.size(); i++)
{
ui->textEdit->append("寄存器"+QString::number(i+1)+":"+QString::number(registers.at(i)));
}
break;

}
@@ -305,7 +292,6 @@ void Widget::on_btn_read_clicked()
quint16 functionCode;
quint16 stratAddress = ui->lineEdit_stratAddress->text().toInt();
quint16 length = ui->lineEdit_length->text().toInt();
QByteArray SendCommand;

if (ui->comboBox_gongnengma->currentIndex() == 0) //读线圈
{
@@ -317,7 +303,7 @@ void Widget::on_btn_read_clicked()
}

modbus->Set(stationAddress,functionCode,stratAddress,length);
modbus->ReadColiAndReg();
modbus->ReadCoilAndReg();

serialPort->write(modbus->SendCommand()); //发送报文
ui->textEdit_2->append("发送报文"+modbus->SendCommand().toHex().toUpper());
@@ -325,64 +311,20 @@ void Widget::on_btn_read_clicked()
ui->pushWrite->setEnabled(0);

comCount = 0;
Sleep(100);
timer.isActive();
timer.start(1000); // 1 s 后触发超时
}

void Widget::on_pushButton_clicked()
void Widget::on_btn_SaveDate_clicked()
{
QString fileName = QFileDialog::getSaveFileName(
this,
"保存文本",
QDir::homePath() + "/note.txt",
"文本文件 (*.txt);;所有文件 (*.*)");

if (fileName.isEmpty())
return;

QFile file(fileName);
if (!file.open(QIODevice::Append | QIODevice::Text)) //
{
QMessageBox::warning(this, "错误", "无法打开文件");
return;
}

// 每次追加前换行
if (file.size() > 0) // 文件非空
file.write("\n"); // 先换行,再写内容

QTextStream out(&file);
out.setCodec("UTF-8");
out << ui->textEdit_2->toPlainText(); // 追加写入
file.close();
SaveDate(this,ui->textEdit_2);
}

void Widget::on_pushButton_2_clicked()
void Widget::on_btn_ReadDate_clicked()
{
QString fileName = QFileDialog::getOpenFileName(
this,
"打开文本",
QDir::homePath(),
"文本文件 (*.txt);;所有文件 (*.*)");

if (fileName.isEmpty())
return;

QFile file(fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
QMessageBox::warning(this, "错误", "无法读取文件");
return;
}

QTextStream in(&file);
in.setCodec("UTF-8");
ui->textEdit_2->setPlainText(in.readAll());
file.close();
ReadDate(this,ui->textEdit_2);
}

void Widget::on_pushButton_3_clicked()
void Widget::on_btn_ClearDate_clicked()
{
ui->textEdit_2->clear();
}
@@ -392,3 +334,8 @@ void Widget::onReadyRead()
recvBuffer.append(serialPort->readAll());
recvTimer->start(50); // 50ms 内无新数据即认为接收完成
}

void Widget::on_btn_ClearRead_clicked()
{
ui->textEdit->clear();
}

+ 5
- 3
widget.h 查看文件

@@ -27,14 +27,16 @@ private slots:

void on_btn_read_clicked();

void on_pushButton_clicked();
void on_btn_SaveDate_clicked();

void on_pushButton_2_clicked();
void on_btn_ReadDate_clicked();

void on_pushButton_3_clicked();
void on_btn_ClearDate_clicked();

void onReadyRead();

void on_btn_ClearRead_clicked();

private:
Ui::Widget *ui;
QSerialPort *serialPort;


+ 406
- 367
widget.ui 查看文件

@@ -6,435 +6,474 @@
<rect>
<x>0</x>
<y>0</y>
<width>787</width>
<height>543</height>
<width>700</width>
<height>486</height>
</rect>
</property>
<property name="windowTitle">
<string>Widget</string>
</property>
<widget class="QLineEdit" name="lineEdit">
<widget class="QGroupBox" name="groupBox">
<property name="geometry">
<rect>
<x>340</x>
<y>430</y>
<width>301</width>
<height>31</height>
<x>30</x>
<y>240</y>
<width>181</width>
<height>231</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="pushWrite">
<property name="geometry">
<rect>
<x>340</x>
<y>470</y>
<width>93</width>
<height>28</height>
</rect>
</property>
<property name="text">
<string>写</string>
</property>
</widget>
<widget class="QTextEdit" name="textEdit">
<property name="geometry">
<rect>
<x>40</x>
<y>280</y>
<width>251</width>
<height>191</height>
</rect>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
<widget class="QPushButton" name="btn_read">
<property name="geometry">
<rect>
<x>200</x>
<y>470</y>
<width>93</width>
<height>28</height>
</rect>
</property>
<property name="text">
<string>读</string>
</property>
</widget>
<widget class="QLabel" name="label_13">
<property name="geometry">
<rect>
<x>340</x>
<y>330</y>
<width>311</width>
<height>101</height>
</rect>
</property>
<property name="text">
<string>写线圈时,使用1、0代表线圈的开关状态,
从左到右依次输入每个线圈的开关;
写寄存器时要写入所有寄存器的16进制数值,
相邻寄存器的值之间用英文&quot;,&quot;分离。</string>
</property>
</widget>
<widget class="QLabel" name="label_4">
<property name="geometry">
<rect>
<x>40</x>
<y>10</y>
<width>72</width>
<height>15</height>
</rect>
</property>
<property name="text">
<string>串口配置</string>
</property>
</widget>
<widget class="QLabel" name="label_5">
<property name="geometry">
<rect>
<x>40</x>
<y>100</y>
<width>72</width>
<height>15</height>
</rect>
</property>
<property name="text">
<property name="title">
<string>从站配置</string>
</property>
</widget>
<widget class="QLabel" name="label_6">
<property name="geometry">
<rect>
<x>40</x>
<y>150</y>
<width>72</width>
<height>15</height>
</rect>
</property>
<property name="text">
<string>状态通知</string>
</property>
</widget>
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>42</x>
<y>32</y>
<width>406</width>
<height>58</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>串口</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QComboBox" name="comboBox_serialNum"/>
</item>
<item row="0" column="3" colspan="2">
<widget class="QLabel" name="label_2">
<property name="text">
<string>波特率</string>
</property>
</widget>
</item>
<item row="0" column="5" colspan="2">
<widget class="QComboBox" name="comboBox_baudRate">
<item>
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>159</width>
<height>131</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>1200</string>
<string>站地址</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>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="comboBox_stationAddress">
<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>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>38400</string>
<string>操作</string>
</property>
</item>
</widget>
</item>
<item row="0" column="7">
<widget class="QLabel" name="label_3">
<property name="text">
<string>数据位</string>
</property>
</widget>
</item>
<item row="0" column="8">
<widget class="QComboBox" name="comboBox_dataBit">
<item>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="comboBox_gongnengma">
<item>
<property name="text">
<string>读线圈</string>
</property>
</item>
<item>
<property name="text">
<string>读寄存器</string>
</property>
</item>
<item>
<property name="text">
<string>写线圈</string>
</property>
</item>
<item>
<property name="text">
<string>写寄存器</string>
</property>
</item>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>5</string>
<string>起始地址</string>
</property>
</item>
<item>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="lineEdit_stratAddress">
<property name="text">
<string>6</string>
<string>256</string>
</property>
</item>
<item>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string>7</string>
<string>长度</string>
</property>
</item>
<item>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="lineEdit_length">
<property name="text">
<string>8</string>
<string>1</string>
</property>
</item>
<item>
</widget>
</item>
</layout>
</widget>
<widget class="QPushButton" name="btn_read">
<property name="geometry">
<rect>
<x>10</x>
<y>160</y>
<width>71</width>
<height>51</height>
</rect>
</property>
<property name="text">
<string>读</string>
</property>
</widget>
<widget class="QPushButton" name="pushWrite">
<property name="geometry">
<rect>
<x>90</x>
<y>160</y>
<width>71</width>
<height>51</height>
</rect>
</property>
<property name="text">
<string>写</string>
</property>
</widget>
</widget>
<widget class="QGroupBox" name="groupBox_2">
<property name="geometry">
<rect>
<x>30</x>
<y>19</y>
<width>181</width>
<height>211</height>
</rect>
</property>
<property name="title">
<string>串口配置</string>
</property>
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>161</width>
<height>181</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>NONE</string>
<string>串口</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="label_7">
<property name="text">
<string>校验位</string>
</property>
</widget>
</item>
<item row="1" column="2" colspan="2">
<widget class="QComboBox" name="comboBox_xiaoyan">
<item>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="comboBox_serialNum"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>无校验(N)</string>
<string>波特率</string>
</property>
</item>
<item>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="comboBox_baudRate">
<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>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>奇校验(O)</string>
<string>数据位</string>
</property>
</item>
<item>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="comboBox_dataBit">
<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>NONE</string>
</property>
</item>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>偶校验(E)</string>
<string>校验位</string>
</property>
</item>
</widget>
</item>
<item row="1" column="4" colspan="2">
<widget class="QLabel" name="label_8">
<property name="text">
<string>停止位</string>
</property>
</widget>
</item>
<item row="1" column="6">
<widget class="QComboBox" name="comboBox_stopBit">
<item>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="comboBox_xiaoyan">
<item>
<property name="text">
<string>无校验(N)</string>
</property>
</item>
<item>
<property name="text">
<string>奇校验(O)</string>
</property>
</item>
<item>
<property name="text">
<string>偶校验(E)</string>
</property>
</item>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>1</string>
<string>停止位</string>
</property>
</item>
<item>
</widget>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="comboBox_stopBit">
<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" colspan="2">
<widget class="QPushButton" name="btnConnect">
<property name="text">
<string>2</string>
<string>连接</string>
</property>
</item>
</widget>
</item>
<item row="1" column="7" colspan="2">
<widget class="QPushButton" name="btnConnect">
<property name="text">
<string>连接</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QGroupBox" name="groupBox_3">
<property name="geometry">
<rect>
<x>240</x>
<y>20</y>
<width>211</width>
<height>271</height>
</rect>
</property>
<property name="title">
<string>数据读取</string>
</property>
<widget class="QTextEdit" name="textEdit">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>191</width>
<height>241</height>
</rect>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</widget>
<widget class="QGroupBox" name="groupBox_4">
<property name="geometry">
<rect>
<x>470</x>
<y>20</y>
<width>221</width>
<height>271</height>
</rect>
</property>
<property name="title">
<string>状态通知</string>
</property>
<widget class="QTextEdit" name="textEdit_2">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>201</width>
<height>241</height>
</rect>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</widget>
<widget class="QGroupBox" name="groupBox_5">
<property name="geometry">
<rect>
<x>240</x>
<y>340</y>
<width>341</width>
<height>131</height>
</rect>
</property>
<property name="title">
<string>写入数据</string>
</property>
<widget class="QLabel" name="label_13">
<property name="geometry">
<rect>
<x>10</x>
<y>0</y>
<width>311</width>
<height>101</height>
</rect>
</property>
<property name="text">
<string>写线圈时,使用1、0代表线圈的开关状态,
从左到右依次输入每个线圈的开关;
写寄存器时要写入所有寄存器的16进制数值,
相邻寄存器的值之间用英文&quot;,&quot;分离。</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit">
<property name="geometry">
<rect>
<x>10</x>
<y>90</y>
<width>301</width>
<height>31</height>
</rect>
</property>
</widget>
</widget>
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>41</x>
<y>116</y>
<width>687</width>
<height>23</height>
<x>240</x>
<y>300</y>
<width>451</width>
<height>30</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_9">
<widget class="QPushButton" name="btn_ClearRead">
<property name="text">
<string>站地址</string>
<string>清空读取信息</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_stationAddress">
<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>
</widget>
</item>
<item>
<widget class="QLabel" name="label_10">
<property name="text">
<string>操作</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_gongnengma">
<item>
<property name="text">
<string>读线圈</string>
</property>
</item>
<item>
<property name="text">
<string>读寄存器</string>
</property>
</item>
<item>
<property name="text">
<string>写线圈</string>
</property>
</item>
<item>
<property name="text">
<string>写寄存器</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QLabel" name="label_11">
<widget class="QPushButton" name="btn_ClearDate">
<property name="text">
<string>起始地址</string>
<string>清空收发信息</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_stratAddress">
<widget class="QPushButton" name="btn_ReadDate">
<property name="text">
<string>256</string>
<string>读取历史收发信息</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_12">
<widget class="QPushButton" name="btn_SaveDate">
<property name="text">
<string>长度</string>
<string>保存收发信息</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_length">
<property name="text">
<string>1</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>41</x>
<y>164</y>
<width>691</width>
<height>91</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QTextEdit" name="textEdit_2"/>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="pushButton_3">
<property name="text">
<string>清空收发信息</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>保存收发信息</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_2">
<property name="text">
<string>读取历史收发信息</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>


正在加载...
取消
保存