MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / onReadReady

Method onReadReady

app/src/IO/Drivers/Modbus.cpp:1297–1336  ·  view source on GitHub ↗

* @brief Handles completed Modbus read operations and publishes the result as RTU-format bytes. */

Source from the content-addressed store, hash-verified

1295 * @brief Handles completed Modbus read operations and publishes the result as RTU-format bytes.
1296 */
1297void IO::Drivers::Modbus::onReadReady()
1298{
1299 auto* reply = qobject_cast<QModbusReply*>(sender());
1300 if (!reply) {
1301 m_lastReply = nullptr;
1302 return;
1303 }
1304
1305 if (reply != m_lastReply) {
1306 reply->deleteLater();
1307 return;
1308 }
1309
1310 m_lastReply = nullptr;
1311
1312 if (reply->error() != QModbusDevice::NoError) {
1313 reply->deleteLater();
1314 return;
1315 }
1316
1317 const QModbusDataUnit unit = reply->result();
1318 if (!unit.isValid() || unit.valueCount() == 0) {
1319 reply->deleteLater();
1320 return;
1321 }
1322
1323 try {
1324 publishReceivedData(buildRtuFrame(unit));
1325 } catch (const std::exception& e) {
1326 qWarning() << "Modbus frame build failed:" << e.what();
1327 } catch (...) {
1328 qWarning() << "Modbus frame build failed: unknown exception";
1329 }
1330
1331 reply->deleteLater();
1332
1333 ++m_currentGroupIndex;
1334 if (m_currentGroupIndex < m_registerGroups.count())
1335 pollNextGroup();
1336}
1337
1338/**
1339 * @brief Handles Modbus device state changes by starting/stopping the poll timer.

Callers

nothing calls this directly

Calls 4

senderFunction · 0.85
errorMethod · 0.80
isValidMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected