Browse Source

基本功能的实现

master
鹏鹏 李 2 weeks ago
parent
commit
f6579d3ccf
2 changed files with 6 additions and 1 deletions
  1. +1
    -1
      modbus.pro.user
  2. +5
    -0
      widget.cpp

+ 1
- 1
modbus.pro.user View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.0.3, 2025-07-25T10:54:01. -->
<!-- Written by QtCreator 4.0.3, 2025-07-25T12:36:51. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>


+ 5
- 0
widget.cpp View File

@@ -7,6 +7,7 @@
#include <QString> #include <QString>
#include <QVector> #include <QVector>
#include <QMessageBox> #include <QMessageBox>
#include <synchapi.h>
#include "crc.h" #include "crc.h"


Widget::Widget(QWidget *parent) : Widget::Widget(QWidget *parent) :
@@ -150,6 +151,7 @@ void Widget::on_pushWrite_clicked()
ui->textEdit_2->append("发送报文"+SendCommand.toHex().toUpper()); ui->textEdit_2->append("发送报文"+SendCommand.toHex().toUpper());
serialPort->write(SendCommand); serialPort->write(SendCommand);


Sleep(100);
timer.isActive(); timer.isActive();
timer.start(2000); // 2 s 后触发超时 timer.start(2000); // 2 s 后触发超时


@@ -202,6 +204,7 @@ void Widget::on_pushWrite_clicked()
ui->textEdit_2->append("发送报文"+SendCommand.toHex().toUpper()); ui->textEdit_2->append("发送报文"+SendCommand.toHex().toUpper());
serialPort->write(SendCommand); serialPort->write(SendCommand);


Sleep(100);
timer.isActive(); timer.isActive();
timer.start(2000); // 2 s 后触发超时 timer.start(2000); // 2 s 后触发超时


@@ -353,6 +356,7 @@ void Widget::on_btn_read_clicked()
{ {
SendCommand.append(0x03); SendCommand.append(0x03);
} }

SendCommand.append(ui->lineEdit_stratAddress->text().toInt()/256); //加入起始地址 SendCommand.append(ui->lineEdit_stratAddress->text().toInt()/256); //加入起始地址
SendCommand.append(ui->lineEdit_stratAddress->text().toInt()%256); SendCommand.append(ui->lineEdit_stratAddress->text().toInt()%256);
SendCommand.append(ui->lineEdit_length->text().toInt()/256); //加入长度 SendCommand.append(ui->lineEdit_length->text().toInt()/256); //加入长度
@@ -367,6 +371,7 @@ void Widget::on_btn_read_clicked()
ui->textEdit_2->append("发送报文"+SendCommand.toHex().toUpper()); ui->textEdit_2->append("发送报文"+SendCommand.toHex().toUpper());
serialPort->write(SendCommand); //发送报文 serialPort->write(SendCommand); //发送报文


Sleep(100);
timer.isActive(); timer.isActive();
timer.start(2000); // 2 s 后触发超时 timer.start(2000); // 2 s 后触发超时
} }

Loading…
Cancel
Save