diff options
Diffstat (limited to 'src/OpcUaMonitoredNode.cpp')
| -rw-r--r-- | src/OpcUaMonitoredNode.cpp | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/OpcUaMonitoredNode.cpp b/src/OpcUaMonitoredNode.cpp index 290a1c2..beec934 100644 --- a/src/OpcUaMonitoredNode.cpp +++ b/src/OpcUaMonitoredNode.cpp @@ -179,6 +179,7 @@ OpcUaMonitoredNode::teardownNode () emit infoChanged (); m_valueType = QOpcUa::Types::Undefined; + m_pendingWrite = false; m_pendingRangeWrite = false; if (m_writable) @@ -312,11 +313,14 @@ OpcUaMonitoredNode::handleAttributeUpdated (QOpcUa::NodeAttribute attr, void OpcUaMonitoredNode::handleValueUpdated (const QVariant &value) { - // After a range write, Qt emits valueAttributeUpdated with only the - // partial written value instead of the full array. Ignore this - // update and let the monitored item deliver the correct full array - // on the next data change notification. - if (m_pendingRangeWrite) + // After a write, Qt emits valueAttributeUpdated from the write path + // before the server's monitored item notification arrives. For regular + // writes this is a duplicate; for range writes it carries only the + // partial written value. Ignore both and let monitoring deliver the + // authoritative value. Removing this guard would give an immediate UI + // update that does not reflect the actual server state, which could be + // useful for optimistic updates. + if (m_pendingWrite || m_pendingRangeWrite) return; // Store the new value pushed by the OPC UA monitored item. @@ -357,6 +361,7 @@ OpcUaMonitoredNode::handleAttributeWritten (QOpcUa::NodeAttribute attr, if (attr != QOpcUa::NodeAttribute::Value) return; + m_pendingWrite = false; m_pendingRangeWrite = false; bool ok = (statusCode == QOpcUa::Good); @@ -560,9 +565,13 @@ OpcUaMonitoredNode::writeValue (const QVariant &value) return; } + m_pendingWrite = true; if (!m_node->writeValueAttribute (coerced, m_valueType)) - emit writeCompleted (false, - QStringLiteral ("Write request failed to dispatch")); + { + m_pendingWrite = false; + emit writeCompleted ( + false, QStringLiteral ("Write request failed to dispatch")); + } } void |
