-
Notifications
You must be signed in to change notification settings - Fork 2
/
modbus.h
61 lines (34 loc) · 1.2 KB
/
modbus.h
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
#ifndef MODBUS_H
#define MODBUS_H
#include <QObject>
#include <QModbusDataUnit>
#include <QModbusRtuSerialMaster>
#include <QSerialPort>
#include <QDebug>
class QModbusReply;
class QModbusClient;
class Modbus : public QObject
{
Q_OBJECT
public:
Modbus();
~Modbus();
bool connectToSlave(const QString port, int baud);
void executeReadRequest(int slaveAdress, int regAdress, int regType); //passing adress of slave, adress of register and register type
void executeWriteRequest(int slaveAdress, int regAdress, int regType, int value); //passing adress of slave, adress of register and register type
void disconnectSlave();
enum RegType { DiscreteInputs = 1, Coils = 2, InputRegisters = 3, HoldingRegisters = 4 };
private:
QModbusReply *modbusReply;
QModbusClient *modbusSlave;
QModbusDataUnit prepareRequest(int regAdress, int regType);
QModbusDataUnit prepareWriteRequest(int regAdress, int regType);
private slots:
void readReady();
void writeRequestFinished();
signals:
void onFinishedWriteRequest(const QString & msg);
void onReadError(const QString & msg);
void onReadReady(const QModbusDataUnit & reg);
};
#endif // MODBUS_H