47 lines
1.3 KiB
C++
47 lines
1.3 KiB
C++
#ifndef MODBUSTCPMANAGER_H
|
|
#define MODBUSTCPMANAGER_H
|
|
|
|
#include "modbusconfig.h"
|
|
|
|
#include <QString>
|
|
#include <QtGlobal>
|
|
|
|
class QModbusTcpClient;
|
|
|
|
class ModbusTcpManager
|
|
{
|
|
public:
|
|
static ModbusTcpManager &instance();
|
|
~ModbusTcpManager();
|
|
|
|
void setConfig(const ModbusConfig &config);
|
|
ModbusConfig config() const;
|
|
|
|
bool connectDevice(QString *error = nullptr);
|
|
void disconnectDevice();
|
|
bool isConnected() const;
|
|
|
|
bool readCoil(int address, bool *value, QString *error = nullptr);
|
|
bool readHoldingRegister(int address, quint16 *value, QString *error = nullptr);
|
|
bool writeCoil(int address, bool value, QString *error = nullptr);
|
|
bool writeHoldingRegister(int address, quint16 value, QString *error = nullptr);
|
|
|
|
QString lastErrorText() const;
|
|
|
|
private:
|
|
ModbusTcpManager();
|
|
ModbusTcpManager(const ModbusTcpManager &) = delete;
|
|
ModbusTcpManager &operator=(const ModbusTcpManager &) = delete;
|
|
|
|
bool readSingleValue(int registerType, int address, quint16 *value, QString *error);
|
|
bool writeSingleValue(int registerType, int address, quint16 value, QString *error);
|
|
void ensureClient();
|
|
void setError(const QString &text, QString *error);
|
|
|
|
ModbusConfig m_config;
|
|
QModbusTcpClient *m_client;
|
|
QString m_lastErrorText;
|
|
};
|
|
|
|
#endif // MODBUSTCPMANAGER_H
|