You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
725 B

#include "modbusmaster.h"
#include <QModbusTcpClient>
#include <QModbusRtuSerialMaster>
#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;
}