-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodbus.h
More file actions
49 lines (28 loc) · 1012 Bytes
/
modbus.h
File metadata and controls
49 lines (28 loc) · 1012 Bytes
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
#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();
bool connectToSlave(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
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();
};
#endif // MODBUS_H