#ifndef MODBUSMASTER_H #define MODBUSMASTER_H #include #include #include #include #include #include #include "SettingSerialParameters.h" class QModbusClient; class QModbusReply; class modBusMaster : public QObject { Q_OBJECT public: explicit modBusMaster(QObject *parent = nullptr); void init(); void open(QString serialPort, int slaveAddress); void start(); void deinit(); void close(); void stop(); 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 registerValues); QBitArray getCoil(int startAddress, quint16 readSize); QBitArray getInputCoil(int startAddress, quint16 readSize); QVector getInputRegister(int startAddress, quint16 readSize); QVector getHoldingRegister(int startAddress, quint16 readSize); QModbusDataUnit readRequest(QModbusDataUnit::RegisterType registerType, int startAddress, quint16 readSize); void writeRequest(QModbusDataUnit::RegisterType registerType, int startAddress, quint16 readSize); bool checkForError(QModbusReply *_reply); signals: void dataFromClient(QString readedParameter); void modbusConnectionState(bool state); public slots: private: QModbusReply *lastRequest; QModbusClient *modbusDevice = nullptr; QString _serialPort ; int _slaveAddress; SettingSerialParameters _modbusSettings; public: QModbusReply *reply; QBitArray m_coils; QVector m_holdingRegisters; }; #endif // MODBUSMASTER_H