You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

65 lines
1.4 KiB

#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
modbusTcpClient = new MyModbusTcp();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_connectBTN_clicked()
{
modbusTcpClient->connectModbusTcp();
}
void MainWindow::on_disconnectBTN_clicked()
{
modbusTcpClient->disconnectModbusTcp();
}
void MainWindow::on_ontimeBTN_clicked()
{
// modbusTcpClient->onTimeReadHR();
timer1 = new QTimer(this); //启动定时器,100ms
connect(timer1, SIGNAL(timeout()), this, SLOT(ontimeRead()));
timer1->start(100); // 每隔1000ms
// modbusTcpClient->readMultipleHR(0,20,1);
}
void MainWindow::ontimeRead(){
modbusTcpClient->readMultipleHR(0, 20, 1);
QString buf;
// int len = sizeof(modbusTcpClient->dataRCV)/sizeof(modbusTcpClient->dataRCV[0]);
for(int i= 0; i<30; i++){
buf.append(QString::number(modbusTcpClient->dataRCV[i]));
buf.append(" ");
}
ui->textEdit->setText(buf);
}
void MainWindow::on_stopOntimeBTN_clicked()
{
timer1->stop();
timer1->deleteLater();
}
void MainWindow::on_pushButton_clicked()
{
modbusTcpClient->writeSingleFloat(0, -3.14f, 1);
}
void MainWindow::on_pushButton_2_clicked()
{
float dataSend[3] = {0.0f, 1.1f, -2.3f};
modbusTcpClient->writeMultipleHR(0, 6, dataSend, 1);
}