#ifndef MODBUSMASTER_H #define MODBUSMASTER_H #include #include #include #include #include #include #include "SettingSerialParameters.h" #include "QWaitCondition" #include "qmutex.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); private: QModbusReply *lastRequest; QModbusClient *modbusDevice = nullptr; QString _serialPort ; int _slaveAddress; SettingSerialParameters _modbusSettings; QBitArray _coilFlags; QVector _registerValues; QWaitCondition modBusAnswerNotReady; QMutex mutex; bool freeThread=false; public: QModbusReply *reply; }; #endif // MODBUSMASTER_H