#include "modbusmaster.h" #include #include #include "serialportexception.h" modBusMaster::modBusMaster(QObject *parent) : QObject(parent) { } void modBusMaster::init() { stop(); modbusDevice = nullptr; modbusDevice = new QModbusRtuSerialMaster(this); connect(modbusDevice, &QModbusClient::errorOccurred, [this](QModbusDevice::Error) { throw serialPortException(modbusDevice->errorString()); }); if (!modbusDevice) throw serialPortException("Could not create Modbus master."); } void modBusMaster::close() { } void modBusMaster::stop() { if (modbusDevice) modbusDevice->disconnectDevice(); delete modbusDevice; }