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.

62 lines
1.8 KiB

#ifndef MODBUSMASTER_H
#define MODBUSMASTER_H
#include <QObject>
#include <QModbusDataUnit>
#include <QModbusRtuSerialMaster>
#include <QtSerialBus/qtserialbusglobal.h>
#include <QBitArray>
#include <QSerialPort>
#include "SettingSerialParameters.h"
class QModbusClient;
class QModbusReply;
class modBusMaster : public QObject
{
Q_OBJECT
public:
explicit modBusMaster(QObject *parent = nullptr);
3 years ago
void init();
void open(QString serialPort, int slaveAddress);
void start();
void deinit();
void close();
void stop();
3 years ago
void setSingleCoil(int startAddress, bool coilFlag);
void setMultipleCoil(int startAddress, quint16 writeSize, QBitArray coilFlags);
void setSingleRegister(int startAddress, quint16 registerValue);
void setMultipleRegister(int startAddress, quint16 writeSize, QVector<quint16> registerValues);
3 years ago
QBitArray getCoil(int startAddress, quint16 readSize);
QBitArray getInputCoil(int startAddress, quint16 readSize);
QVector<quint16> getInputRegister(int startAddress, quint16 readSize);
QVector<quint16> getHoldingRegister(int startAddress, quint16 readSize);
3 years ago
QModbusDataUnit readRequest(QModbusDataUnit::RegisterType registerType, int startAddress, quint16 readSize);
void writeRequest(QModbusDataUnit::RegisterType registerType, int startAddress, quint16 readSize);
3 years ago
bool checkForError(QModbusReply *_reply);
signals:
void dataFromClient(QString readedParameter);
void modbusConnectionState(bool state);
private:
QModbusReply *lastRequest;
QModbusClient *modbusDevice = nullptr;
QString _serialPort ;
int _slaveAddress;
SettingSerialParameters _modbusSettings;
3 years ago
QBitArray _coilFlags;
QVector<quint16> _registerValues;
public:
QModbusReply *reply;
};
#endif // MODBUSMASTER_H