-
Notifications
You must be signed in to change notification settings - Fork 13
/
mainwindow.cpp
63 lines (55 loc) · 1.7 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/****************************************************************************
**
** SPDX-License-Identifier: LGPL-3.0-or-later
** SPDX-FileCopyrightText: 2012 - present, Karol Drożak <[email protected]>
**
****************************************************************************/
#include <QDebug>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "qmodbusregisters.h"
using namespace Modbus;
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
//modbus = new QModbusMaster("127.0.0.1", 502, this);
//modbus->connect();
QModbusMaster modbusMaster("127.0.0.1", 502);
modbusMaster.connect();
// wektor rejestrow o adresie poczatkowym 0 i dlugosci 4
QModbusRegisters reg(0, 4);
// odczyt 4 rejestrow od adresu 0
modbusMaster.readRegisters(reg);
if(modbusMaster.lastError().isValid()) {
qDebug()<<"ERROR"<<modbusMaster.lastError().message();
}
else {
qDebug()<<reg
<<reg.getBitString(0)
<<reg.getInteger64(0)
<<reg.getInteger32(0)
<<reg.getFloat32(0);
}
modbusMaster.close();
/*
QModbusMaster modbusMaster("127.0.0.1", 502);
modbusMaster.connect();
QModbusRegisters reg(modbusMaster, 0, 4);
if(!reg.read()) {
qDebug()<<reg.lastError().text();
}
else {
qDebug()<<reg
<<reg.getBitString(0)
<<reg.getInteger64(0)
<<reg.getInteger32(0)
<<reg.getFloat32(0);
}
modbusMaster.close();
*/
}
MainWindow::~MainWindow()
{
delete ui;
//modbus->close();
}