Update inepro plugin to libnyma-modbus
This commit is contained in:
parent
5d4d8beb56
commit
c947b51023
@ -1,14 +1,13 @@
|
||||
include(../plugins.pri)
|
||||
|
||||
QT += serialport serialbus
|
||||
# Generate modbus connection
|
||||
MODBUS_CONNECTIONS += pro380-registers.json
|
||||
#MODBUS_TOOLS_CONFIG += VERBOSE
|
||||
include(../modbus.pri)
|
||||
|
||||
HEADERS += \
|
||||
integrationplugininepro.h \
|
||||
pro380modbusrtuconnection.h \
|
||||
../modbus/modbusdatautils.h
|
||||
integrationplugininepro.h
|
||||
|
||||
SOURCES += \
|
||||
integrationplugininepro.cpp \
|
||||
pro380modbusrtuconnection.cpp \
|
||||
../modbus/modbusdatautils.cpp
|
||||
integrationplugininepro.cpp
|
||||
|
||||
|
||||
@ -45,7 +45,7 @@ void IntegrationPluginInepro::init()
|
||||
qCWarning(dcInepro()) << "Modbus RTU hardware resource removed for" << thing << ". The thing will not be functional any more until a new resource has been configured for it.";
|
||||
thing->setStateValue(pro380ConnectedStateTypeId, false);
|
||||
|
||||
delete m_pro380Connections.take(thing);
|
||||
delete m_connections.take(thing);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -101,9 +101,9 @@ void IntegrationPluginInepro::setupThing(ThingSetupInfo *info)
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_pro380Connections.contains(thing)) {
|
||||
if (m_connections.contains(thing)) {
|
||||
qCDebug(dcInepro()) << "Setup after rediscovery, cleaning up ...";
|
||||
m_pro380Connections.take(thing)->deleteLater();
|
||||
m_connections.take(thing)->deleteLater();
|
||||
}
|
||||
|
||||
Pro380ModbusRtuConnection *proConnection = new Pro380ModbusRtuConnection(hardwareManager()->modbusRtuResource()->getModbusRtuMaster(uuid), address, this);
|
||||
@ -194,7 +194,7 @@ void IntegrationPluginInepro::setupThing(ThingSetupInfo *info)
|
||||
|
||||
|
||||
// FIXME: try to read before setup success
|
||||
m_pro380Connections.insert(thing, proConnection);
|
||||
m_connections.insert(thing, proConnection);
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
}
|
||||
|
||||
@ -205,7 +205,7 @@ void IntegrationPluginInepro::postSetupThing(Thing *thing)
|
||||
m_refreshTimer = hardwareManager()->pluginTimerManager()->registerTimer(2);
|
||||
connect(m_refreshTimer, &PluginTimer::timeout, this, [this] {
|
||||
foreach (Thing *thing, myThings()) {
|
||||
m_pro380Connections.value(thing)->update();
|
||||
m_connections.value(thing)->update();
|
||||
}
|
||||
});
|
||||
|
||||
@ -218,8 +218,8 @@ void IntegrationPluginInepro::thingRemoved(Thing *thing)
|
||||
{
|
||||
qCDebug(dcInepro()) << "Thing removed" << thing->name();
|
||||
|
||||
if (m_pro380Connections.contains(thing))
|
||||
m_pro380Connections.take(thing)->deleteLater();
|
||||
if (m_connections.contains(thing))
|
||||
m_connections.take(thing)->deleteLater();
|
||||
|
||||
if (myThings().isEmpty() && m_refreshTimer) {
|
||||
qCDebug(dcInepro()) << "Stopping reconnect timer";
|
||||
|
||||
@ -37,8 +37,6 @@
|
||||
|
||||
#include "pro380modbusrtuconnection.h"
|
||||
|
||||
#include "extern-plugininfo.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QTimer>
|
||||
|
||||
@ -59,8 +57,8 @@ public:
|
||||
|
||||
private:
|
||||
PluginTimer *m_refreshTimer = nullptr;
|
||||
QHash<Thing *, Pro380ModbusRtuConnection *> m_connections;
|
||||
|
||||
QHash<Thing *, Pro380ModbusRtuConnection *> m_pro380Connections;
|
||||
};
|
||||
|
||||
#endif // INTEGRATIONPLUGININEPRO_H
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{
|
||||
"className": "Pro380",
|
||||
"protocol": "RTU",
|
||||
"endianness": "BigEndian",
|
||||
"blocks": [
|
||||
@ -263,4 +264,4 @@
|
||||
"access": "RO"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,537 +0,0 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2021, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This fileDescriptor is part of nymea.
|
||||
* This project including source code and documentation is protected by
|
||||
* copyright law, and remains the property of nymea GmbH. All rights, including
|
||||
* reproduction, publication, editing and translation, are reserved. The use of
|
||||
* this project is subject to the terms of a license agreement to be concluded
|
||||
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
|
||||
* under https://nymea.io/license
|
||||
*
|
||||
* GNU Lesser General Public License Usage
|
||||
* Alternatively, this project may be redistributed and/or modified under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; version 3. This project is distributed in the hope that
|
||||
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this project. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For any further details and any questions please contact us under
|
||||
* contact@nymea.io or see our FAQ/Licensing Information on
|
||||
* https://nymea.io/license/faq
|
||||
*
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
|
||||
#include "pro380modbusrtuconnection.h"
|
||||
#include "loggingcategories.h"
|
||||
|
||||
NYMEA_LOGGING_CATEGORY(dcPro380ModbusRtuConnection, "Pro380ModbusRtuConnection")
|
||||
|
||||
Pro380ModbusRtuConnection::Pro380ModbusRtuConnection(ModbusRtuMaster *modbusRtuMaster, quint16 slaveId, QObject *parent) :
|
||||
QObject(parent),
|
||||
m_modbusRtuMaster(modbusRtuMaster),
|
||||
m_slaveId(slaveId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ModbusRtuMaster *Pro380ModbusRtuConnection::modbusRtuMaster() const
|
||||
{
|
||||
return m_modbusRtuMaster;
|
||||
}
|
||||
quint16 Pro380ModbusRtuConnection::slaveId() const
|
||||
{
|
||||
return m_slaveId;
|
||||
}
|
||||
float Pro380ModbusRtuConnection::frequency() const
|
||||
{
|
||||
return m_frequency;
|
||||
}
|
||||
|
||||
float Pro380ModbusRtuConnection::totalEnergyConsumed() const
|
||||
{
|
||||
return m_totalEnergyConsumed;
|
||||
}
|
||||
|
||||
float Pro380ModbusRtuConnection::totalEnergyProduced() const
|
||||
{
|
||||
return m_totalEnergyProduced;
|
||||
}
|
||||
|
||||
float Pro380ModbusRtuConnection::voltagePhaseA() const
|
||||
{
|
||||
return m_voltagePhaseA;
|
||||
}
|
||||
|
||||
float Pro380ModbusRtuConnection::voltagePhaseB() const
|
||||
{
|
||||
return m_voltagePhaseB;
|
||||
}
|
||||
|
||||
float Pro380ModbusRtuConnection::voltagePhaseC() const
|
||||
{
|
||||
return m_voltagePhaseC;
|
||||
}
|
||||
|
||||
float Pro380ModbusRtuConnection::currentPhaseA() const
|
||||
{
|
||||
return m_currentPhaseA;
|
||||
}
|
||||
|
||||
float Pro380ModbusRtuConnection::currentPhaseB() const
|
||||
{
|
||||
return m_currentPhaseB;
|
||||
}
|
||||
|
||||
float Pro380ModbusRtuConnection::currentPhaseC() const
|
||||
{
|
||||
return m_currentPhaseC;
|
||||
}
|
||||
|
||||
float Pro380ModbusRtuConnection::totalCurrentPower() const
|
||||
{
|
||||
return m_totalCurrentPower;
|
||||
}
|
||||
|
||||
float Pro380ModbusRtuConnection::powerPhaseA() const
|
||||
{
|
||||
return m_powerPhaseA;
|
||||
}
|
||||
|
||||
float Pro380ModbusRtuConnection::powerPhaseB() const
|
||||
{
|
||||
return m_powerPhaseB;
|
||||
}
|
||||
|
||||
float Pro380ModbusRtuConnection::powerPhaseC() const
|
||||
{
|
||||
return m_powerPhaseC;
|
||||
}
|
||||
|
||||
float Pro380ModbusRtuConnection::energyConsumedPhaseA() const
|
||||
{
|
||||
return m_energyConsumedPhaseA;
|
||||
}
|
||||
|
||||
float Pro380ModbusRtuConnection::energyConsumedPhaseB() const
|
||||
{
|
||||
return m_energyConsumedPhaseB;
|
||||
}
|
||||
|
||||
float Pro380ModbusRtuConnection::energyConsumedPhaseC() const
|
||||
{
|
||||
return m_energyConsumedPhaseC;
|
||||
}
|
||||
|
||||
float Pro380ModbusRtuConnection::energyProducedPhaseA() const
|
||||
{
|
||||
return m_energyProducedPhaseA;
|
||||
}
|
||||
|
||||
float Pro380ModbusRtuConnection::energyProducedPhaseB() const
|
||||
{
|
||||
return m_energyProducedPhaseB;
|
||||
}
|
||||
|
||||
float Pro380ModbusRtuConnection::energyProducedPhaseC() const
|
||||
{
|
||||
return m_energyProducedPhaseC;
|
||||
}
|
||||
|
||||
void Pro380ModbusRtuConnection::initialize()
|
||||
{
|
||||
// No init registers defined. Nothing to be done and we are finished.
|
||||
emit initializationFinished();
|
||||
}
|
||||
|
||||
void Pro380ModbusRtuConnection::update()
|
||||
{
|
||||
updateFrequency();
|
||||
updateTotalEnergyConsumed();
|
||||
updateTotalEnergyProduced();
|
||||
updatePhasesVoltageBlock();
|
||||
updatePhasesCurrentBlock();
|
||||
updateCurrentPowerBlock();
|
||||
updatePhasesEnergyConsumedBlock();
|
||||
updatePhasesEnergyProducedBlock();
|
||||
}
|
||||
|
||||
void Pro380ModbusRtuConnection::updateFrequency()
|
||||
{
|
||||
// Update registers from Frequency
|
||||
qCDebug(dcPro380ModbusRtuConnection()) << "--> Read \"Frequency\" register:" << 20488 << "size:" << 2;
|
||||
ModbusRtuReply *reply = readFrequency();
|
||||
if (reply) {
|
||||
if (!reply->isFinished()) {
|
||||
connect(reply, &ModbusRtuReply::finished, this, [this, reply](){
|
||||
if (reply->error() == ModbusRtuReply::NoError) {
|
||||
QVector<quint16> values = reply->result();
|
||||
qCDebug(dcPro380ModbusRtuConnection()) << "<-- Response from \"Frequency\" register" << 20488 << "size:" << 2 << values;
|
||||
float receivedFrequency = ModbusDataUtils::convertToFloat32(values, ModbusDataUtils::ByteOrderBigEndian);
|
||||
if (m_frequency != receivedFrequency) {
|
||||
m_frequency = receivedFrequency;
|
||||
emit frequencyChanged(m_frequency);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
connect(reply, &ModbusRtuReply::errorOccurred, this, [reply] (ModbusRtuReply::Error error){
|
||||
qCWarning(dcPro380ModbusRtuConnection()) << "ModbusRtu reply error occurred while updating \"Frequency\" registers" << error << reply->errorString();
|
||||
emit reply->finished();
|
||||
});
|
||||
}
|
||||
} else {
|
||||
qCWarning(dcPro380ModbusRtuConnection()) << "Error occurred while reading \"Frequency\" registers";
|
||||
}
|
||||
}
|
||||
|
||||
void Pro380ModbusRtuConnection::updateTotalEnergyConsumed()
|
||||
{
|
||||
// Update registers from Total energy consumed (Forward active energy)
|
||||
qCDebug(dcPro380ModbusRtuConnection()) << "--> Read \"Total energy consumed (Forward active energy)\" register:" << 24588 << "size:" << 2;
|
||||
ModbusRtuReply *reply = readTotalEnergyConsumed();
|
||||
if (reply) {
|
||||
if (!reply->isFinished()) {
|
||||
connect(reply, &ModbusRtuReply::finished, this, [this, reply](){
|
||||
if (reply->error() == ModbusRtuReply::NoError) {
|
||||
QVector<quint16> values = reply->result();
|
||||
qCDebug(dcPro380ModbusRtuConnection()) << "<-- Response from \"Total energy consumed (Forward active energy)\" register" << 24588 << "size:" << 2 << values;
|
||||
float receivedTotalEnergyConsumed = ModbusDataUtils::convertToFloat32(values, ModbusDataUtils::ByteOrderBigEndian);
|
||||
if (m_totalEnergyConsumed != receivedTotalEnergyConsumed) {
|
||||
m_totalEnergyConsumed = receivedTotalEnergyConsumed;
|
||||
emit totalEnergyConsumedChanged(m_totalEnergyConsumed);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
connect(reply, &ModbusRtuReply::errorOccurred, this, [reply] (ModbusRtuReply::Error error){
|
||||
qCWarning(dcPro380ModbusRtuConnection()) << "ModbusRtu reply error occurred while updating \"Total energy consumed (Forward active energy)\" registers" << error << reply->errorString();
|
||||
emit reply->finished();
|
||||
});
|
||||
}
|
||||
} else {
|
||||
qCWarning(dcPro380ModbusRtuConnection()) << "Error occurred while reading \"Total energy consumed (Forward active energy)\" registers";
|
||||
}
|
||||
}
|
||||
|
||||
void Pro380ModbusRtuConnection::updateTotalEnergyProduced()
|
||||
{
|
||||
// Update registers from Total energy produced (Reverse active energy)
|
||||
qCDebug(dcPro380ModbusRtuConnection()) << "--> Read \"Total energy produced (Reverse active energy)\" register:" << 24600 << "size:" << 2;
|
||||
ModbusRtuReply *reply = readTotalEnergyProduced();
|
||||
if (reply) {
|
||||
if (!reply->isFinished()) {
|
||||
connect(reply, &ModbusRtuReply::finished, this, [this, reply](){
|
||||
if (reply->error() == ModbusRtuReply::NoError) {
|
||||
QVector<quint16> values = reply->result();
|
||||
qCDebug(dcPro380ModbusRtuConnection()) << "<-- Response from \"Total energy produced (Reverse active energy)\" register" << 24600 << "size:" << 2 << values;
|
||||
float receivedTotalEnergyProduced = ModbusDataUtils::convertToFloat32(values, ModbusDataUtils::ByteOrderBigEndian);
|
||||
if (m_totalEnergyProduced != receivedTotalEnergyProduced) {
|
||||
m_totalEnergyProduced = receivedTotalEnergyProduced;
|
||||
emit totalEnergyProducedChanged(m_totalEnergyProduced);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
connect(reply, &ModbusRtuReply::errorOccurred, this, [reply] (ModbusRtuReply::Error error){
|
||||
qCWarning(dcPro380ModbusRtuConnection()) << "ModbusRtu reply error occurred while updating \"Total energy produced (Reverse active energy)\" registers" << error << reply->errorString();
|
||||
emit reply->finished();
|
||||
});
|
||||
}
|
||||
} else {
|
||||
qCWarning(dcPro380ModbusRtuConnection()) << "Error occurred while reading \"Total energy produced (Reverse active energy)\" registers";
|
||||
}
|
||||
}
|
||||
|
||||
void Pro380ModbusRtuConnection::updatePhasesVoltageBlock()
|
||||
{
|
||||
// Update register block "phasesVoltage"
|
||||
qCDebug(dcPro380ModbusRtuConnection()) << "--> Read block \"phasesVoltage\" registers from:" << 20482 << "size:" << 6;
|
||||
ModbusRtuReply *reply = m_modbusRtuMaster->readHoldingRegister(m_slaveId, 20482, 6);
|
||||
if (reply) {
|
||||
if (!reply->isFinished()) {
|
||||
connect(reply, &ModbusRtuReply::finished, this, [this, reply](){
|
||||
if (reply->error() == ModbusRtuReply::NoError) {
|
||||
QVector<quint16> blockValues = reply->result();
|
||||
QVector<quint16> values;
|
||||
qCDebug(dcPro380ModbusRtuConnection()) << "<-- Response from reading block \"phasesVoltage\" register" << 20482 << "size:" << 6 << blockValues;
|
||||
values = blockValues.mid(0, 2);
|
||||
float receivedVoltagePhaseA = ModbusDataUtils::convertToFloat32(values, ModbusDataUtils::ByteOrderBigEndian);
|
||||
if (m_voltagePhaseA != receivedVoltagePhaseA) {
|
||||
m_voltagePhaseA = receivedVoltagePhaseA;
|
||||
emit voltagePhaseAChanged(m_voltagePhaseA);
|
||||
}
|
||||
|
||||
values = blockValues.mid(2, 2);
|
||||
float receivedVoltagePhaseB = ModbusDataUtils::convertToFloat32(values, ModbusDataUtils::ByteOrderBigEndian);
|
||||
if (m_voltagePhaseB != receivedVoltagePhaseB) {
|
||||
m_voltagePhaseB = receivedVoltagePhaseB;
|
||||
emit voltagePhaseBChanged(m_voltagePhaseB);
|
||||
}
|
||||
|
||||
values = blockValues.mid(4, 2);
|
||||
float receivedVoltagePhaseC = ModbusDataUtils::convertToFloat32(values, ModbusDataUtils::ByteOrderBigEndian);
|
||||
if (m_voltagePhaseC != receivedVoltagePhaseC) {
|
||||
m_voltagePhaseC = receivedVoltagePhaseC;
|
||||
emit voltagePhaseCChanged(m_voltagePhaseC);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
connect(reply, &ModbusRtuReply::errorOccurred, this, [reply] (ModbusRtuReply::Error error){
|
||||
qCWarning(dcPro380ModbusRtuConnection()) << "ModbusRtu reply error occurred while updating block \"phasesVoltage\" registers" << error << reply->errorString();
|
||||
emit reply->finished();
|
||||
});
|
||||
}
|
||||
} else {
|
||||
qCWarning(dcPro380ModbusRtuConnection()) << "Error occurred while reading block \"phasesVoltage\" registers";
|
||||
}
|
||||
}
|
||||
|
||||
void Pro380ModbusRtuConnection::updatePhasesCurrentBlock()
|
||||
{
|
||||
// Update register block "phasesCurrent"
|
||||
qCDebug(dcPro380ModbusRtuConnection()) << "--> Read block \"phasesCurrent\" registers from:" << 20492 << "size:" << 6;
|
||||
ModbusRtuReply *reply = m_modbusRtuMaster->readHoldingRegister(m_slaveId, 20492, 6);
|
||||
if (reply) {
|
||||
if (!reply->isFinished()) {
|
||||
connect(reply, &ModbusRtuReply::finished, this, [this, reply](){
|
||||
if (reply->error() == ModbusRtuReply::NoError) {
|
||||
QVector<quint16> blockValues = reply->result();
|
||||
QVector<quint16> values;
|
||||
qCDebug(dcPro380ModbusRtuConnection()) << "<-- Response from reading block \"phasesCurrent\" register" << 20492 << "size:" << 6 << blockValues;
|
||||
values = blockValues.mid(0, 2);
|
||||
float receivedCurrentPhaseA = ModbusDataUtils::convertToFloat32(values, ModbusDataUtils::ByteOrderBigEndian);
|
||||
if (m_currentPhaseA != receivedCurrentPhaseA) {
|
||||
m_currentPhaseA = receivedCurrentPhaseA;
|
||||
emit currentPhaseAChanged(m_currentPhaseA);
|
||||
}
|
||||
|
||||
values = blockValues.mid(2, 2);
|
||||
float receivedCurrentPhaseB = ModbusDataUtils::convertToFloat32(values, ModbusDataUtils::ByteOrderBigEndian);
|
||||
if (m_currentPhaseB != receivedCurrentPhaseB) {
|
||||
m_currentPhaseB = receivedCurrentPhaseB;
|
||||
emit currentPhaseBChanged(m_currentPhaseB);
|
||||
}
|
||||
|
||||
values = blockValues.mid(4, 2);
|
||||
float receivedCurrentPhaseC = ModbusDataUtils::convertToFloat32(values, ModbusDataUtils::ByteOrderBigEndian);
|
||||
if (m_currentPhaseC != receivedCurrentPhaseC) {
|
||||
m_currentPhaseC = receivedCurrentPhaseC;
|
||||
emit currentPhaseCChanged(m_currentPhaseC);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
connect(reply, &ModbusRtuReply::errorOccurred, this, [reply] (ModbusRtuReply::Error error){
|
||||
qCWarning(dcPro380ModbusRtuConnection()) << "ModbusRtu reply error occurred while updating block \"phasesCurrent\" registers" << error << reply->errorString();
|
||||
emit reply->finished();
|
||||
});
|
||||
}
|
||||
} else {
|
||||
qCWarning(dcPro380ModbusRtuConnection()) << "Error occurred while reading block \"phasesCurrent\" registers";
|
||||
}
|
||||
}
|
||||
|
||||
void Pro380ModbusRtuConnection::updateCurrentPowerBlock()
|
||||
{
|
||||
// Update register block "currentPower"
|
||||
qCDebug(dcPro380ModbusRtuConnection()) << "--> Read block \"currentPower\" registers from:" << 20498 << "size:" << 8;
|
||||
ModbusRtuReply *reply = m_modbusRtuMaster->readHoldingRegister(m_slaveId, 20498, 8);
|
||||
if (reply) {
|
||||
if (!reply->isFinished()) {
|
||||
connect(reply, &ModbusRtuReply::finished, this, [this, reply](){
|
||||
if (reply->error() == ModbusRtuReply::NoError) {
|
||||
QVector<quint16> blockValues = reply->result();
|
||||
QVector<quint16> values;
|
||||
qCDebug(dcPro380ModbusRtuConnection()) << "<-- Response from reading block \"currentPower\" register" << 20498 << "size:" << 8 << blockValues;
|
||||
values = blockValues.mid(0, 2);
|
||||
float receivedTotalCurrentPower = ModbusDataUtils::convertToFloat32(values, ModbusDataUtils::ByteOrderBigEndian);
|
||||
if (m_totalCurrentPower != receivedTotalCurrentPower) {
|
||||
m_totalCurrentPower = receivedTotalCurrentPower;
|
||||
emit totalCurrentPowerChanged(m_totalCurrentPower);
|
||||
}
|
||||
|
||||
values = blockValues.mid(2, 2);
|
||||
float receivedPowerPhaseA = ModbusDataUtils::convertToFloat32(values, ModbusDataUtils::ByteOrderBigEndian);
|
||||
if (m_powerPhaseA != receivedPowerPhaseA) {
|
||||
m_powerPhaseA = receivedPowerPhaseA;
|
||||
emit powerPhaseAChanged(m_powerPhaseA);
|
||||
}
|
||||
|
||||
values = blockValues.mid(4, 2);
|
||||
float receivedPowerPhaseB = ModbusDataUtils::convertToFloat32(values, ModbusDataUtils::ByteOrderBigEndian);
|
||||
if (m_powerPhaseB != receivedPowerPhaseB) {
|
||||
m_powerPhaseB = receivedPowerPhaseB;
|
||||
emit powerPhaseBChanged(m_powerPhaseB);
|
||||
}
|
||||
|
||||
values = blockValues.mid(6, 2);
|
||||
float receivedPowerPhaseC = ModbusDataUtils::convertToFloat32(values, ModbusDataUtils::ByteOrderBigEndian);
|
||||
if (m_powerPhaseC != receivedPowerPhaseC) {
|
||||
m_powerPhaseC = receivedPowerPhaseC;
|
||||
emit powerPhaseCChanged(m_powerPhaseC);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
connect(reply, &ModbusRtuReply::errorOccurred, this, [reply] (ModbusRtuReply::Error error){
|
||||
qCWarning(dcPro380ModbusRtuConnection()) << "ModbusRtu reply error occurred while updating block \"currentPower\" registers" << error << reply->errorString();
|
||||
emit reply->finished();
|
||||
});
|
||||
}
|
||||
} else {
|
||||
qCWarning(dcPro380ModbusRtuConnection()) << "Error occurred while reading block \"currentPower\" registers";
|
||||
}
|
||||
}
|
||||
|
||||
void Pro380ModbusRtuConnection::updatePhasesEnergyConsumedBlock()
|
||||
{
|
||||
// Update register block "phasesEnergyConsumed"
|
||||
qCDebug(dcPro380ModbusRtuConnection()) << "--> Read block \"phasesEnergyConsumed\" registers from:" << 24594 << "size:" << 6;
|
||||
ModbusRtuReply *reply = m_modbusRtuMaster->readHoldingRegister(m_slaveId, 24594, 6);
|
||||
if (reply) {
|
||||
if (!reply->isFinished()) {
|
||||
connect(reply, &ModbusRtuReply::finished, this, [this, reply](){
|
||||
if (reply->error() == ModbusRtuReply::NoError) {
|
||||
QVector<quint16> blockValues = reply->result();
|
||||
QVector<quint16> values;
|
||||
qCDebug(dcPro380ModbusRtuConnection()) << "<-- Response from reading block \"phasesEnergyConsumed\" register" << 24594 << "size:" << 6 << blockValues;
|
||||
values = blockValues.mid(0, 2);
|
||||
float receivedEnergyConsumedPhaseA = ModbusDataUtils::convertToFloat32(values, ModbusDataUtils::ByteOrderBigEndian);
|
||||
if (m_energyConsumedPhaseA != receivedEnergyConsumedPhaseA) {
|
||||
m_energyConsumedPhaseA = receivedEnergyConsumedPhaseA;
|
||||
emit energyConsumedPhaseAChanged(m_energyConsumedPhaseA);
|
||||
}
|
||||
|
||||
values = blockValues.mid(2, 2);
|
||||
float receivedEnergyConsumedPhaseB = ModbusDataUtils::convertToFloat32(values, ModbusDataUtils::ByteOrderBigEndian);
|
||||
if (m_energyConsumedPhaseB != receivedEnergyConsumedPhaseB) {
|
||||
m_energyConsumedPhaseB = receivedEnergyConsumedPhaseB;
|
||||
emit energyConsumedPhaseBChanged(m_energyConsumedPhaseB);
|
||||
}
|
||||
|
||||
values = blockValues.mid(4, 2);
|
||||
float receivedEnergyConsumedPhaseC = ModbusDataUtils::convertToFloat32(values, ModbusDataUtils::ByteOrderBigEndian);
|
||||
if (m_energyConsumedPhaseC != receivedEnergyConsumedPhaseC) {
|
||||
m_energyConsumedPhaseC = receivedEnergyConsumedPhaseC;
|
||||
emit energyConsumedPhaseCChanged(m_energyConsumedPhaseC);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
connect(reply, &ModbusRtuReply::errorOccurred, this, [reply] (ModbusRtuReply::Error error){
|
||||
qCWarning(dcPro380ModbusRtuConnection()) << "ModbusRtu reply error occurred while updating block \"phasesEnergyConsumed\" registers" << error << reply->errorString();
|
||||
emit reply->finished();
|
||||
});
|
||||
}
|
||||
} else {
|
||||
qCWarning(dcPro380ModbusRtuConnection()) << "Error occurred while reading block \"phasesEnergyConsumed\" registers";
|
||||
}
|
||||
}
|
||||
|
||||
void Pro380ModbusRtuConnection::updatePhasesEnergyProducedBlock()
|
||||
{
|
||||
// Update register block "phasesEnergyProduced"
|
||||
qCDebug(dcPro380ModbusRtuConnection()) << "--> Read block \"phasesEnergyProduced\" registers from:" << 24606 << "size:" << 6;
|
||||
ModbusRtuReply *reply = m_modbusRtuMaster->readHoldingRegister(m_slaveId, 24606, 6);
|
||||
if (reply) {
|
||||
if (!reply->isFinished()) {
|
||||
connect(reply, &ModbusRtuReply::finished, this, [this, reply](){
|
||||
if (reply->error() == ModbusRtuReply::NoError) {
|
||||
QVector<quint16> blockValues = reply->result();
|
||||
QVector<quint16> values;
|
||||
qCDebug(dcPro380ModbusRtuConnection()) << "<-- Response from reading block \"phasesEnergyProduced\" register" << 24606 << "size:" << 6 << blockValues;
|
||||
values = blockValues.mid(0, 2);
|
||||
float receivedEnergyProducedPhaseA = ModbusDataUtils::convertToFloat32(values, ModbusDataUtils::ByteOrderBigEndian);
|
||||
if (m_energyProducedPhaseA != receivedEnergyProducedPhaseA) {
|
||||
m_energyProducedPhaseA = receivedEnergyProducedPhaseA;
|
||||
emit energyProducedPhaseAChanged(m_energyProducedPhaseA);
|
||||
}
|
||||
|
||||
values = blockValues.mid(2, 2);
|
||||
float receivedEnergyProducedPhaseB = ModbusDataUtils::convertToFloat32(values, ModbusDataUtils::ByteOrderBigEndian);
|
||||
if (m_energyProducedPhaseB != receivedEnergyProducedPhaseB) {
|
||||
m_energyProducedPhaseB = receivedEnergyProducedPhaseB;
|
||||
emit energyProducedPhaseBChanged(m_energyProducedPhaseB);
|
||||
}
|
||||
|
||||
values = blockValues.mid(4, 2);
|
||||
float receivedEnergyProducedPhaseC = ModbusDataUtils::convertToFloat32(values, ModbusDataUtils::ByteOrderBigEndian);
|
||||
if (m_energyProducedPhaseC != receivedEnergyProducedPhaseC) {
|
||||
m_energyProducedPhaseC = receivedEnergyProducedPhaseC;
|
||||
emit energyProducedPhaseCChanged(m_energyProducedPhaseC);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
connect(reply, &ModbusRtuReply::errorOccurred, this, [reply] (ModbusRtuReply::Error error){
|
||||
qCWarning(dcPro380ModbusRtuConnection()) << "ModbusRtu reply error occurred while updating block \"phasesEnergyProduced\" registers" << error << reply->errorString();
|
||||
emit reply->finished();
|
||||
});
|
||||
}
|
||||
} else {
|
||||
qCWarning(dcPro380ModbusRtuConnection()) << "Error occurred while reading block \"phasesEnergyProduced\" registers";
|
||||
}
|
||||
}
|
||||
|
||||
ModbusRtuReply *Pro380ModbusRtuConnection::readFrequency()
|
||||
{
|
||||
return m_modbusRtuMaster->readHoldingRegister(m_slaveId, 20488, 2);
|
||||
}
|
||||
|
||||
ModbusRtuReply *Pro380ModbusRtuConnection::readTotalEnergyConsumed()
|
||||
{
|
||||
return m_modbusRtuMaster->readHoldingRegister(m_slaveId, 24588, 2);
|
||||
}
|
||||
|
||||
ModbusRtuReply *Pro380ModbusRtuConnection::readTotalEnergyProduced()
|
||||
{
|
||||
return m_modbusRtuMaster->readHoldingRegister(m_slaveId, 24600, 2);
|
||||
}
|
||||
|
||||
void Pro380ModbusRtuConnection::verifyInitFinished()
|
||||
{
|
||||
if (m_pendingInitReplies.isEmpty()) {
|
||||
qCDebug(dcPro380ModbusRtuConnection()) << "Initialization finished of Pro380ModbusRtuConnection";
|
||||
emit initializationFinished();
|
||||
}
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug debug, Pro380ModbusRtuConnection *pro380ModbusRtuConnection)
|
||||
{
|
||||
debug.nospace().noquote() << "Pro380ModbusRtuConnection(" << pro380ModbusRtuConnection->modbusRtuMaster()->modbusUuid().toString() << ", " << pro380ModbusRtuConnection->modbusRtuMaster()->serialPort() << ", slave ID:" << pro380ModbusRtuConnection->slaveId() << ")" << "\n";
|
||||
debug.nospace().noquote() << " - Frequency:" << pro380ModbusRtuConnection->frequency() << " [Hz]" << "\n";
|
||||
debug.nospace().noquote() << " - Total energy consumed (Forward active energy):" << pro380ModbusRtuConnection->totalEnergyConsumed() << " [kWh]" << "\n";
|
||||
debug.nospace().noquote() << " - Total energy produced (Reverse active energy):" << pro380ModbusRtuConnection->totalEnergyProduced() << " [kWh]" << "\n";
|
||||
debug.nospace().noquote() << " - Voltage phase L1:" << pro380ModbusRtuConnection->voltagePhaseA() << " [V]" << "\n";
|
||||
debug.nospace().noquote() << " - Voltage phase L2:" << pro380ModbusRtuConnection->voltagePhaseB() << " [V]" << "\n";
|
||||
debug.nospace().noquote() << " - Voltage phase L3:" << pro380ModbusRtuConnection->voltagePhaseC() << " [V]" << "\n";
|
||||
debug.nospace().noquote() << " - Current phase L1:" << pro380ModbusRtuConnection->currentPhaseA() << " [A]" << "\n";
|
||||
debug.nospace().noquote() << " - Current phase L2:" << pro380ModbusRtuConnection->currentPhaseB() << " [A]" << "\n";
|
||||
debug.nospace().noquote() << " - Current phase L3:" << pro380ModbusRtuConnection->currentPhaseC() << " [A]" << "\n";
|
||||
debug.nospace().noquote() << " - Total system power:" << pro380ModbusRtuConnection->totalCurrentPower() << " [kW]" << "\n";
|
||||
debug.nospace().noquote() << " - Power phase L1:" << pro380ModbusRtuConnection->powerPhaseA() << " [kW]" << "\n";
|
||||
debug.nospace().noquote() << " - Power phase L2:" << pro380ModbusRtuConnection->powerPhaseB() << " [kW]" << "\n";
|
||||
debug.nospace().noquote() << " - Power phase L3:" << pro380ModbusRtuConnection->powerPhaseC() << " [kW]" << "\n";
|
||||
debug.nospace().noquote() << " - Energy consumed phase A:" << pro380ModbusRtuConnection->energyConsumedPhaseA() << " [kWh]" << "\n";
|
||||
debug.nospace().noquote() << " - Energy consumed phase B:" << pro380ModbusRtuConnection->energyConsumedPhaseB() << " [kWh]" << "\n";
|
||||
debug.nospace().noquote() << " - Energy consumed phase C:" << pro380ModbusRtuConnection->energyConsumedPhaseC() << " [kWh]" << "\n";
|
||||
debug.nospace().noquote() << " - Energy produced phase A:" << pro380ModbusRtuConnection->energyProducedPhaseA() << " [kWh]" << "\n";
|
||||
debug.nospace().noquote() << " - Energy produced phase B:" << pro380ModbusRtuConnection->energyProducedPhaseB() << " [kWh]" << "\n";
|
||||
debug.nospace().noquote() << " - Energy produced phase C:" << pro380ModbusRtuConnection->energyProducedPhaseC() << " [kWh]" << "\n";
|
||||
return debug.quote().space();
|
||||
}
|
||||
|
||||
@ -1,204 +0,0 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2021, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This fileDescriptor is part of nymea.
|
||||
* This project including source code and documentation is protected by
|
||||
* copyright law, and remains the property of nymea GmbH. All rights, including
|
||||
* reproduction, publication, editing and translation, are reserved. The use of
|
||||
* this project is subject to the terms of a license agreement to be concluded
|
||||
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
|
||||
* under https://nymea.io/license
|
||||
*
|
||||
* GNU Lesser General Public License Usage
|
||||
* Alternatively, this project may be redistributed and/or modified under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; version 3. This project is distributed in the hope that
|
||||
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this project. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For any further details and any questions please contact us under
|
||||
* contact@nymea.io or see our FAQ/Licensing Information on
|
||||
* https://nymea.io/license/faq
|
||||
*
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#ifndef PRO380MODBUSRTUCONNECTION_H
|
||||
#define PRO380MODBUSRTUCONNECTION_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "../modbus/modbusdatautils.h"
|
||||
#include <hardware/modbus/modbusrtumaster.h>
|
||||
|
||||
class Pro380ModbusRtuConnection : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Pro380ModbusRtuConnection(ModbusRtuMaster *modbusRtuMaster, quint16 slaveId, QObject *parent = nullptr);
|
||||
~Pro380ModbusRtuConnection() = default;
|
||||
|
||||
ModbusRtuMaster *modbusRtuMaster() const;
|
||||
quint16 slaveId() const;
|
||||
|
||||
/* Frequency [Hz] - Address: 20488, Size: 2 */
|
||||
float frequency() const;
|
||||
|
||||
/* Total energy consumed (Forward active energy) [kWh] - Address: 24588, Size: 2 */
|
||||
float totalEnergyConsumed() const;
|
||||
|
||||
/* Total energy produced (Reverse active energy) [kWh] - Address: 24600, Size: 2 */
|
||||
float totalEnergyProduced() const;
|
||||
|
||||
/* Voltage phase L1 [V] - Address: 20482, Size: 2 */
|
||||
float voltagePhaseA() const;
|
||||
|
||||
/* Voltage phase L2 [V] - Address: 20484, Size: 2 */
|
||||
float voltagePhaseB() const;
|
||||
|
||||
/* Voltage phase L3 [V] - Address: 20486, Size: 2 */
|
||||
float voltagePhaseC() const;
|
||||
|
||||
/* Read block from start addess 20482 with size of 6 registers containing following 3 properties:
|
||||
- Voltage phase L1 [V] - Address: 20482, Size: 2
|
||||
- Voltage phase L2 [V] - Address: 20484, Size: 2
|
||||
- Voltage phase L3 [V] - Address: 20486, Size: 2
|
||||
*/
|
||||
void updatePhasesVoltageBlock();
|
||||
/* Current phase L1 [A] - Address: 20492, Size: 2 */
|
||||
float currentPhaseA() const;
|
||||
|
||||
/* Current phase L2 [A] - Address: 20494, Size: 2 */
|
||||
float currentPhaseB() const;
|
||||
|
||||
/* Current phase L3 [A] - Address: 20496, Size: 2 */
|
||||
float currentPhaseC() const;
|
||||
|
||||
/* Read block from start addess 20492 with size of 6 registers containing following 3 properties:
|
||||
- Current phase L1 [A] - Address: 20492, Size: 2
|
||||
- Current phase L2 [A] - Address: 20494, Size: 2
|
||||
- Current phase L3 [A] - Address: 20496, Size: 2
|
||||
*/
|
||||
void updatePhasesCurrentBlock();
|
||||
/* Total system power [kW] - Address: 20498, Size: 2 */
|
||||
float totalCurrentPower() const;
|
||||
|
||||
/* Power phase L1 [kW] - Address: 20500, Size: 2 */
|
||||
float powerPhaseA() const;
|
||||
|
||||
/* Power phase L2 [kW] - Address: 20502, Size: 2 */
|
||||
float powerPhaseB() const;
|
||||
|
||||
/* Power phase L3 [kW] - Address: 20504, Size: 2 */
|
||||
float powerPhaseC() const;
|
||||
|
||||
/* Read block from start addess 20498 with size of 8 registers containing following 4 properties:
|
||||
- Total system power [kW] - Address: 20498, Size: 2
|
||||
- Power phase L1 [kW] - Address: 20500, Size: 2
|
||||
- Power phase L2 [kW] - Address: 20502, Size: 2
|
||||
- Power phase L3 [kW] - Address: 20504, Size: 2
|
||||
*/
|
||||
void updateCurrentPowerBlock();
|
||||
/* Energy consumed phase A [kWh] - Address: 24594, Size: 2 */
|
||||
float energyConsumedPhaseA() const;
|
||||
|
||||
/* Energy consumed phase B [kWh] - Address: 24596, Size: 2 */
|
||||
float energyConsumedPhaseB() const;
|
||||
|
||||
/* Energy consumed phase C [kWh] - Address: 24598, Size: 2 */
|
||||
float energyConsumedPhaseC() const;
|
||||
|
||||
/* Read block from start addess 24594 with size of 6 registers containing following 3 properties:
|
||||
- Energy consumed phase A [kWh] - Address: 24594, Size: 2
|
||||
- Energy consumed phase B [kWh] - Address: 24596, Size: 2
|
||||
- Energy consumed phase C [kWh] - Address: 24598, Size: 2
|
||||
*/
|
||||
void updatePhasesEnergyConsumedBlock();
|
||||
/* Energy produced phase A [kWh] - Address: 24606, Size: 2 */
|
||||
float energyProducedPhaseA() const;
|
||||
|
||||
/* Energy produced phase B [kWh] - Address: 24608, Size: 2 */
|
||||
float energyProducedPhaseB() const;
|
||||
|
||||
/* Energy produced phase C [kWh] - Address: 24610, Size: 2 */
|
||||
float energyProducedPhaseC() const;
|
||||
|
||||
/* Read block from start addess 24606 with size of 6 registers containing following 3 properties:
|
||||
- Energy produced phase A [kWh] - Address: 24606, Size: 2
|
||||
- Energy produced phase B [kWh] - Address: 24608, Size: 2
|
||||
- Energy produced phase C [kWh] - Address: 24610, Size: 2
|
||||
*/
|
||||
void updatePhasesEnergyProducedBlock();
|
||||
|
||||
void updateFrequency();
|
||||
void updateTotalEnergyConsumed();
|
||||
void updateTotalEnergyProduced();
|
||||
|
||||
virtual void initialize();
|
||||
virtual void update();
|
||||
|
||||
signals:
|
||||
void initializationFinished();
|
||||
|
||||
void frequencyChanged(float frequency);
|
||||
void totalEnergyConsumedChanged(float totalEnergyConsumed);
|
||||
void totalEnergyProducedChanged(float totalEnergyProduced);
|
||||
void voltagePhaseAChanged(float voltagePhaseA);
|
||||
void voltagePhaseBChanged(float voltagePhaseB);
|
||||
void voltagePhaseCChanged(float voltagePhaseC);
|
||||
void currentPhaseAChanged(float currentPhaseA);
|
||||
void currentPhaseBChanged(float currentPhaseB);
|
||||
void currentPhaseCChanged(float currentPhaseC);
|
||||
void totalCurrentPowerChanged(float totalCurrentPower);
|
||||
void powerPhaseAChanged(float powerPhaseA);
|
||||
void powerPhaseBChanged(float powerPhaseB);
|
||||
void powerPhaseCChanged(float powerPhaseC);
|
||||
void energyConsumedPhaseAChanged(float energyConsumedPhaseA);
|
||||
void energyConsumedPhaseBChanged(float energyConsumedPhaseB);
|
||||
void energyConsumedPhaseCChanged(float energyConsumedPhaseC);
|
||||
void energyProducedPhaseAChanged(float energyProducedPhaseA);
|
||||
void energyProducedPhaseBChanged(float energyProducedPhaseB);
|
||||
void energyProducedPhaseCChanged(float energyProducedPhaseC);
|
||||
|
||||
private:
|
||||
ModbusRtuMaster *m_modbusRtuMaster = nullptr;
|
||||
quint16 m_slaveId = 1;
|
||||
QVector<ModbusRtuReply *> m_pendingInitReplies;
|
||||
|
||||
float m_frequency = 0;
|
||||
float m_totalEnergyConsumed = 0;
|
||||
float m_totalEnergyProduced = 0;
|
||||
float m_voltagePhaseA = 0;
|
||||
float m_voltagePhaseB = 0;
|
||||
float m_voltagePhaseC = 0;
|
||||
float m_currentPhaseA = 0;
|
||||
float m_currentPhaseB = 0;
|
||||
float m_currentPhaseC = 0;
|
||||
float m_totalCurrentPower = 0;
|
||||
float m_powerPhaseA = 0;
|
||||
float m_powerPhaseB = 0;
|
||||
float m_powerPhaseC = 0;
|
||||
float m_energyConsumedPhaseA = 0;
|
||||
float m_energyConsumedPhaseB = 0;
|
||||
float m_energyConsumedPhaseC = 0;
|
||||
float m_energyProducedPhaseA = 0;
|
||||
float m_energyProducedPhaseB = 0;
|
||||
float m_energyProducedPhaseC = 0;
|
||||
|
||||
void verifyInitFinished();
|
||||
|
||||
ModbusRtuReply *readFrequency();
|
||||
ModbusRtuReply *readTotalEnergyConsumed();
|
||||
ModbusRtuReply *readTotalEnergyProduced();
|
||||
|
||||
|
||||
};
|
||||
|
||||
QDebug operator<<(QDebug debug, Pro380ModbusRtuConnection *pro380ModbusRtuConnection);
|
||||
|
||||
#endif // PRO380MODBUSRTUCONNECTION_H
|
||||
Reference in New Issue
Block a user