#ifndef MODBUSMASTER_H #define MODBUSMASTER_H #include #include #include #include #include #if QT_CONFIG(modbus_serialport) #include #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 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