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.
 
 

66 lines
1.7 KiB

#ifndef MODBUSMASTER_H
#define MODBUSMASTER_H
#include <QObject>
#include <QModbusDataUnit>
#include <QModbusRtuSerialMaster>
#include <QtSerialBus/qtserialbusglobal.h>
#include <QBitArray>
#if QT_CONFIG(modbus_serialport)
#include <QSerialPort>
#endif
class QModbusClient;
class QModbusReply;
class modBusMaster : public QObject
{
Q_OBJECT
public:
explicit modBusMaster(QObject *parent = nullptr);
void init();
void open(QString _serialPort , int _serverId);
void start();
void deinit();
void close();
void stop();
void setSingleCoil();
void setMultipleCoil();
void setSingleRgister();
void setMultipleRegister();
void getCoil(int startAddress, quint16 readSize);
void getInputCoil(int startAddress, quint16 readSize);
void getInputRegister(int startAddress, quint16 readSize);
void getHoldingRegister(int startAddress, quint16 readSize);
void readRequest(QModbusDataUnit::RegisterType registerType, int startAddress, quint16 readSize);
void writeRequest(QModbusDataUnit::RegisterType registerType, int startAddress, quint16 readSize);
signals:
public slots:
void readReady();
private:
QModbusReply *lastRequest;
QModbusClient *modbusDevice;
QString serialPort ;
int serverId;
public:
QModbusReply *reply;
QBitArray m_coils;
QVector<quint16> m_holdingRegisters;
struct Settings {
#if QT_CONFIG(modbus_serialport)
int parity = QSerialPort::EvenParity;
int baud = QSerialPort::Baud19200;
int dataBits = QSerialPort::Data8;
int stopBits = QSerialPort::OneStop;
#endif
int responseTime = 1000;
int numberOfRetries = 3;
} modbusSettings;
};
#endif // MODBUSMASTER_H