summaryrefslogtreecommitdiffstats
path: root/examples/serialbus/modbus/custom/mainwindow.h
blob: 991da3c57a90d248127a2dc61166777d1148062e (plain)
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
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include "modbusclient.h"
#include "modbusserver.h"

#include <QHash>
#include <QMainWindow>

QT_BEGIN_NAMESPACE

class QLineEdit;

namespace Ui {
class MainWindow;
}

QT_END_NAMESPACE

class RegisterModel;

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private Q_SLOTS:
    void onConnectButtonClicked();
    void onStateChanged(int state);

    void onReadReady();
    void onReadButtonClicked();
    void onWriteButtonClicked();

    void setRegister(const QString &value);
    void updateWidgets(QModbusDataUnit::RegisterType table, int address, int size);

private:
    void setupConnections();
    void setupClientContainer();
    void setupServerContainer();

private:
    Ui::MainWindow *ui = nullptr;
    RegisterModel *m_model = nullptr;

    ModbusClient m_client;
    ModbusServer m_server;
    QHash<QString, QLineEdit *> m_registers;
};

#endif // MAINWINDOW_H