summaryrefslogtreecommitdiffstats
path: root/src/OpcUaMonitoredNode.h
diff options
context:
space:
mode:
authorThomas Vanbesien <tvanbesi@proton.me>2026-02-20 12:59:07 +0100
committerThomas Vanbesien <tvanbesi@proton.me>2026-02-20 13:06:24 +0100
commit47227acd25c59a1d4b2961c0e1b1eb879e68adec (patch)
treeb814869a40def023ebb5d0f35931f848c384f122 /src/OpcUaMonitoredNode.h
parent263a055f9b9460e4da747c7e56372e963f72fe68 (diff)
downloadBobinkQtOpcUa-master.tar.gz
BobinkQtOpcUa-master.zip
Add write support with automatic type coercion to OpcUaMonitoredNodeHEADmaster
writeValue() Q_INVOKABLE coerces QML JS types to the exact C++ type expected by the OPC UA node (auto-detected from DataType attribute via opcUaDataTypeToQOpcUaType). Handles all scalar types, booleans, and comma-separated array input. Adds writable property derived from AccessLevel bits. Demo shows inline TextField + Write button for writable nodes, "(READ-ONLY)" for others.
Diffstat (limited to 'src/OpcUaMonitoredNode.h')
-rw-r--r--src/OpcUaMonitoredNode.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/OpcUaMonitoredNode.h b/src/OpcUaMonitoredNode.h
index ac5983a..5895bea 100644
--- a/src/OpcUaMonitoredNode.h
+++ b/src/OpcUaMonitoredNode.h
@@ -57,6 +57,7 @@ class OpcUaMonitoredNode : public QObject, public QQmlParserStatus
Q_PROPERTY (
bool monitored READ monitored WRITE setMonitored NOTIFY monitoredChanged)
Q_PROPERTY (QVariant value READ value NOTIFY valueChanged)
+ Q_PROPERTY (bool writable READ writable NOTIFY writableChanged)
Q_PROPERTY (OpcUaNodeInfo info READ info NOTIFY infoChanged)
public:
@@ -69,8 +70,19 @@ public:
void setMonitored (bool monitored);
QVariant value () const;
+ bool writable () const;
OpcUaNodeInfo info () const;
+ /**
+ * @brief Write a value to the OPC UA node.
+ *
+ * Coerces @a value to the node's data type (auto-detected from the
+ * server's DataType attribute). For array nodes, a comma-separated
+ * string is split and each element coerced individually.
+ * Result is reported asynchronously via writeCompleted().
+ */
+ Q_INVOKABLE void writeValue (const QVariant &value);
+
void classBegin () override;
void componentComplete () override;
@@ -78,23 +90,30 @@ signals:
void nodeIdChanged ();
void monitoredChanged ();
void valueChanged ();
+ void writableChanged ();
void infoChanged ();
+ void writeCompleted (bool success, const QString &message);
private slots:
void handleAttributeUpdated (QOpcUa::NodeAttribute attr,
const QVariant &value);
void handleValueUpdated (const QVariant &value);
void handleClientConnectedChanged ();
+ void handleAttributeWritten (QOpcUa::NodeAttribute attr,
+ QOpcUa::UaStatusCode statusCode);
private:
void setupNode ();
void teardownNode ();
+ QVariant coerceValue (const QVariant &input) const;
QString m_nodeId;
bool m_monitored = true;
bool m_componentComplete = false;
QOpcUaNode *m_node = nullptr;
+ QOpcUa::Types m_valueType = QOpcUa::Types::Undefined;
+ bool m_writable = false;
QVariant m_value;
OpcUaNodeInfo m_info;
};