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.
59 lines
1.6 KiB
59 lines
1.6 KiB
#ifndef MODBUSMASTER_H
|
|
#define MODBUSMASTER_H
|
|
|
|
#include <QObject>
|
|
#include <QModbusDevice>
|
|
#include <QBitArray>
|
|
#include <QModbusDataUnit>
|
|
|
|
#include "ServoException.h"
|
|
#include "ModbusConfig.h"
|
|
|
|
#include "ExpConfig.h"
|
|
|
|
class QModbusClient;
|
|
class QModbusReply;
|
|
|
|
class ModbusMaster : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
private:
|
|
bool _initialized = false;
|
|
QModbusClient* _modbusDevice = nullptr;
|
|
int _clientAddress;
|
|
QModbusDataUnit _modbusReplyUnit;
|
|
QBitArray _coilsToWrite;
|
|
QVector<quint16> _RegistersToWrite;
|
|
|
|
public:
|
|
explicit ModbusMaster(QObject* parent = nullptr);
|
|
|
|
void readRequest(QModbusDataUnit::RegisterType registerType,
|
|
int startAddress,
|
|
quint16 readSize);
|
|
void checkForError(QModbusReply* _reply);
|
|
void writeRequest(QModbusDataUnit::RegisterType registerType,
|
|
int startAddress,
|
|
quint16 writeSize);
|
|
|
|
//uncrustify off
|
|
public slots:
|
|
//uncrustify on
|
|
void init();
|
|
|
|
void connectToDevice(ModbusConfig modbusConfig);
|
|
void connectionStateChanged(QModbusDevice::State state);
|
|
|
|
QBitArray getCoil(int startAddress, quint16 readSize, ExpConfig& expConfig);
|
|
QBitArray getInputCoil(int startAddress, quint16 readSize);
|
|
QVector<quint16> getHoldingRegister(int startAddress, quint16 readSize);
|
|
QVector<quint16> getInputRegister(int startAddress, quint16 readSize);
|
|
|
|
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);
|
|
};
|
|
|
|
#endif //MODBUSMASTER_H
|
|
|