Fix building and JSON RPC for modbus management

This commit is contained in:
Simon Stürz 2021-02-15 17:33:09 +01:00
parent 9967b1007d
commit 1f247b30be
3 changed files with 18 additions and 2 deletions

View File

@ -121,7 +121,7 @@ ModbusRtuHandler::ModbusRtuHandler(ModbusRtuManager *modbusRtuManager, QObject *
// ReconfigureModbusRtuMaster
params.clear(); returns.clear();
description = "Rconfigure the modbus RTU master with the given UUID and configuration.";
description = "Reconfigure the modbus RTU master with the given UUID and configuration.";
params.insert("modbusUuid", enumValueName(Uuid));
params.insert("serialPort", enumValueName(String));
params.insert("baudrate", enumValueName(Uint));
@ -141,7 +141,7 @@ ModbusRtuHandler::ModbusRtuHandler(ModbusRtuManager *modbusRtuManager, QObject *
connect(modbusRtuManager->serialPortMonitor(), &SerialPortMonitor::serialPortRemoved, this, [=](const SerialPort &serialPort){
QVariantMap params;
params.insert("serialPort", pack(serialPort));
emit SerialPortAdded(params);
emit SerialPortRemoved(params);
});

View File

@ -49,6 +49,7 @@ class ModbusRtuManager : public QObject
public:
enum ModbusRtuError {
ModbusRtuErrorNoError,
ModbusRtuErrorNotAvailable,
ModbusRtuErrorUuidNotFound,
ModbusRtuErrorHardwareNotFound,
ModbusRtuErrorConnectionFailed

View File

@ -157,17 +157,26 @@ bool ModbusRtuMasterImpl::connected() const
bool ModbusRtuMasterImpl::connectDevice()
{
#ifdef WITH_QTSERIALBUS
m_modbus->setConnectionParameter(QModbusDevice::SerialPortNameParameter, m_serialPort);
m_modbus->setConnectionParameter(QModbusDevice::SerialBaudRateParameter, m_baudrate);
m_modbus->setConnectionParameter(QModbusDevice::SerialDataBitsParameter, m_dataBits);
m_modbus->setConnectionParameter(QModbusDevice::SerialStopBitsParameter, m_stopBits);
m_modbus->setConnectionParameter(QModbusDevice::SerialParityParameter, m_parity);
return m_modbus->connectDevice();
#else
qCWarning(dcModbusRtu()) << "Modbus is not available on this platform.";
return false;
#endif
}
void ModbusRtuMasterImpl::disconnectDevice()
{
#ifdef WITH_QTSERIALBUS
m_modbus->disconnectDevice();
#else
qCWarning(dcModbusRtu()) << "Modbus is not available on this platform.";
#endif
}
ModbusRtuReply *ModbusRtuMasterImpl::readCoil(int slaveAddress, int registerAddress, quint16 size)
@ -217,6 +226,7 @@ ModbusRtuReply *ModbusRtuMasterImpl::readCoil(int slaveAddress, int registerAddr
Q_UNUSED(slaveAddress)
Q_UNUSED(registerAddress)
Q_UNUSED(size)
qCWarning(dcModbusRtu()) << "Modbus is not available on this platform.";
return nullptr;
#endif
@ -269,6 +279,7 @@ ModbusRtuReply *ModbusRtuMasterImpl::readDiscreteInput(int slaveAddress, int reg
Q_UNUSED(slaveAddress)
Q_UNUSED(registerAddress)
Q_UNUSED(size)
qCWarning(dcModbusRtu()) << "Modbus is not available on this platform.";
return nullptr;
#endif
@ -321,6 +332,7 @@ ModbusRtuReply *ModbusRtuMasterImpl::readInputRegister(int slaveAddress, int reg
Q_UNUSED(slaveAddress)
Q_UNUSED(registerAddress)
Q_UNUSED(size)
qCWarning(dcModbusRtu()) << "Modbus is not available on this platform.";
return nullptr;
#endif
@ -373,6 +385,7 @@ ModbusRtuReply *ModbusRtuMasterImpl::readHoldingRegister(int slaveAddress, int r
Q_UNUSED(slaveAddress)
Q_UNUSED(registerAddress)
Q_UNUSED(size)
qCWarning(dcModbusRtu()) << "Modbus is not available on this platform.";
return nullptr;
#endif
@ -427,6 +440,7 @@ ModbusRtuReply *ModbusRtuMasterImpl::writeCoils(int slaveAddress, int registerAd
Q_UNUSED(slaveAddress)
Q_UNUSED(registerAddress)
Q_UNUSED(values)
qCWarning(dcModbusRtu()) << "Modbus is not available on this platform.";
return nullptr;
#endif
@ -482,6 +496,7 @@ ModbusRtuReply *ModbusRtuMasterImpl::writeHoldingRegisters(int slaveAddress, int
Q_UNUSED(slaveAddress)
Q_UNUSED(registerAddress)
Q_UNUSED(values)
qCWarning(dcModbusRtu()) << "Modbus is not available on this platform.";
return nullptr;
#endif