summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Keller <Rainer.Keller@qt.io>2019-04-05 10:08:31 +0200
committerRainer Keller <Rainer.Keller@qt.io>2019-04-17 13:35:11 +0000
commit61a2c26fe8831a0a743efd0e179bbe9bf9425235 (patch)
treef9312f9379d7861127a9c3f1222d69a50f1e4980
parent789a7a40d21cc46d4c84992f1e028758591411de (diff)
qml: Add batch write supportv5.13.0-beta3
Change-Id: I480aec4a6e71e8904a5a8322874d216ea4fec607 Reviewed-by: Jannis Völker <jannis.voelker@basyskom.com>
-rw-r--r--src/imports/opcua/opcua.pro4
-rw-r--r--src/imports/opcua/opcua_plugin.cpp9
-rw-r--r--src/imports/opcua/opcuaconnection.cpp106
-rw-r--r--src/imports/opcua/opcuaconnection.h3
-rw-r--r--src/imports/opcua/opcuawriteitem.cpp262
-rw-r--r--src/imports/opcua/opcuawriteitem.h109
-rw-r--r--src/imports/opcua/opcuawriteresult.cpp161
-rw-r--r--src/imports/opcua/opcuawriteresult.h82
-rw-r--r--tests/auto/declarative/BatchReadWriteTest.qml (renamed from tests/auto/declarative/BatchReadTest.qml)101
-rw-r--r--tests/auto/declarative/tst_batchReadWrite.qml41
10 files changed, 878 insertions, 0 deletions
diff --git a/src/imports/opcua/opcua.pro b/src/imports/opcua/opcua.pro
index eb0cbe3..e53cf6c 100644
--- a/src/imports/opcua/opcua.pro
+++ b/src/imports/opcua/opcua.pro
@@ -20,6 +20,8 @@ SOURCES += \
opcuareadresult.cpp \
opcuaserverdiscovery.cpp \
opcuastatus.cpp \
+ opcuawriteitem.cpp \
+ opcuawriteresult.cpp \
HEADERS += \
opcua_plugin.h \
@@ -41,6 +43,8 @@ HEADERS += \
opcuareadresult.h \
opcuaserverdiscovery.h \
opcuastatus.h \
+ opcuawriteitem.h \
+ opcuawriteresult.h \
load(qml_plugin)
diff --git a/src/imports/opcua/opcua_plugin.cpp b/src/imports/opcua/opcua_plugin.cpp
index 2ebf44a..d4aaa63 100644
--- a/src/imports/opcua/opcua_plugin.cpp
+++ b/src/imports/opcua/opcua_plugin.cpp
@@ -48,6 +48,8 @@
#include "opcuareaditem.h"
#include "opcuareadresult.h"
#include "opcuaserverdiscovery.h"
+#include "opcuawriteitem.h"
+#include "opcuawriteresult.h"
#include <QLoggingCategory>
#include <QOpcUaUserTokenPolicy>
@@ -131,8 +133,15 @@ void OpcUaPlugin::registerTypes(const char *uri)
return new OpcUaReadItemFactory();
});
+ qmlRegisterSingletonType<OpcUaWriteItemFactory>(uri, major, minor, "WriteItem", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject* {
+ Q_UNUSED(engine)
+ Q_UNUSED(scriptEngine)
+ return new OpcUaWriteItemFactory();
+ });
qRegisterMetaType<OpcUaReadItem>();
qRegisterMetaType<OpcUaReadResult>();
+ qRegisterMetaType<OpcUaWriteItem>();
+ qRegisterMetaType<OpcUaWriteResult>();
qmlRegisterType<OpcUaEndpointDiscovery>(uri, major, minor, "EndpointDiscovery");
qmlRegisterType<OpcUaServerDiscovery>(uri, major, minor, "ServerDiscovery");
diff --git a/src/imports/opcua/opcuaconnection.cpp b/src/imports/opcua/opcuaconnection.cpp
index 7d62e25..93ec5ad 100644
--- a/src/imports/opcua/opcuaconnection.cpp
+++ b/src/imports/opcua/opcuaconnection.cpp
@@ -36,12 +36,15 @@
#include "opcuaconnection.h"
#include "opcuareadresult.h"
+#include "opcuawriteitem.h"
+#include "opcuawriteresult.h"
#include "universalnode.h"
#include <QJSEngine>
#include <QLoggingCategory>
#include <QOpcUaProvider>
#include <QOpcUaReadItem>
#include <QOpcUaReadResult>
+#include <QOpcUaWriteItem>
QT_BEGIN_NAMESPACE
@@ -247,6 +250,7 @@ void OpcUaConnection::setBackend(const QString &name)
});
m_client->setNamespaceAutoupdate(true);
connect(m_client, &QOpcUaClient::readNodeAttributesFinished, this, &OpcUaConnection::handleReadNodeAttributesFinished);
+ connect(m_client, &QOpcUaClient::writeNodeAttributesFinished, this, &OpcUaConnection::handleWriteNodeAttributesFinished);
} else {
qCWarning(QT_OPCUA_PLUGINS_QML) << tr("Backend '%1' could not be created.").arg(name);
}
@@ -435,6 +439,98 @@ bool OpcUaConnection::readNodeAttributes(const QJSValue &value)
return m_client->readNodeAttributes(readItemList);
}
+/*!
+ \qmlmethod Connection::writeNodeAttributes(valuesToBeWritten)
+
+ This function is used to write multiple values to a server in one go.
+ Returns \c true if the write request was dispatched successfully.
+
+ The values to be written have to be passed as JavaScript array of \l WriteItem.
+
+ \code
+ // List of items to write
+ var writeItemList = [];
+ // Item to be added to the list of items to be written
+ var writeItem;
+
+ // Prepare an item to be written
+
+ // Create a new write item and fill properties
+ writeItem = QtOpcUa.WriteItem.create();
+ writeItem.ns = "http://qt-project.org";
+ writeItem.nodeId = "s=Demo.Static.Scalar.Double";
+ writeItem.attribute = QtOpcUa.Constants.NodeAttribute.Value;
+ writeItem.value = 32.1;
+ writeItem.valueType = QtOpcUa.Constants.Double;
+
+ // Add the prepared item to the list of items to be written
+ writeItemList.push(writeItem);
+
+ // Add further items
+ [...]
+
+ if (!connection.writeNodeAttributes(writeItemList)) {
+ // handle error
+ }
+ \endcode
+
+ The result of the write request are provided by the signal
+ \l writeNodeAttributesFinished().
+
+ \sa writeNodeAttributesFinished(), WriteItem
+*/
+bool OpcUaConnection::writeNodeAttributes(const QJSValue &value)
+{
+ if (!m_client || !m_connected) {
+ qCWarning(QT_OPCUA_PLUGINS_QML) << tr("Not connected to server.");
+ return false;
+ }
+ if (!value.isArray()) {
+ qCWarning(QT_OPCUA_PLUGINS_QML) << tr("List of WriteItems it not an array.");
+ return false;
+ }
+
+ QVector<QOpcUaWriteItem> writeItemList;
+
+ for (int i = 0; i < value.property("length").toInt(); ++i){
+ const auto &writeItem = qjsvalue_cast<OpcUaWriteItem>(value.property(i));
+ if (writeItem.nodeId().isEmpty()) {
+ qCWarning(QT_OPCUA_PLUGINS_QML) << tr("Invalid WriteItem in list of items at index %1").arg(i);
+ return false;
+ }
+
+ QString finalNode;
+ bool ok;
+ int index = writeItem.namespaceIdentifier().toInt(&ok);
+ if (ok) {
+ QString identifier;
+ UniversalNode::splitNodeIdAndNamespace(writeItem.nodeId(), nullptr, &identifier);
+ finalNode = UniversalNode::createNodeString(index, identifier);
+ } else {
+ finalNode = UniversalNode::resolveNamespaceToNode(writeItem.nodeId(), writeItem.namespaceIdentifier().toString(), m_client);
+ }
+
+ if (finalNode.isEmpty()) {
+ qCWarning(QT_OPCUA_PLUGINS_QML) << tr("Failed to resolve node.");
+ return false;
+ }
+
+ auto tmp = QOpcUaWriteItem(finalNode,
+ writeItem.attribute(),
+ writeItem.value(),
+ writeItem.valueType(),
+ writeItem.indexRange());
+
+ tmp.setSourceTimestamp(writeItem.sourceTimestamp());
+ tmp.setServerTimestamp(writeItem.serverTimestamp());
+ if (writeItem.hasStatusCode())
+ tmp.setStatusCode(static_cast<QOpcUa::UaStatusCode>(writeItem.statusCode()));
+ writeItemList.push_back(tmp);
+ }
+
+ return m_client->writeNodeAttributes(writeItemList);
+}
+
QStringList OpcUaConnection::supportedSecurityPolicies() const
{
if (!m_client)
@@ -469,4 +565,14 @@ void OpcUaConnection::handleReadNodeAttributesFinished(const QVector<QOpcUaReadR
emit readNodeAttributesFinished(QVariant::fromValue(returnValue));
}
+void OpcUaConnection::handleWriteNodeAttributesFinished(const QVector<QOpcUaWriteResult> &results)
+{
+ QVariantList returnValue;
+
+ for (const auto &result : results)
+ returnValue.append(QVariant::fromValue(OpcUaWriteResult(result, m_client)));
+
+ emit writeNodeAttributesFinished(QVariant::fromValue(returnValue));
+}
+
QT_END_NAMESPACE
diff --git a/src/imports/opcua/opcuaconnection.h b/src/imports/opcua/opcuaconnection.h
index 29590ca..a072a65 100644
--- a/src/imports/opcua/opcuaconnection.h
+++ b/src/imports/opcua/opcuaconnection.h
@@ -77,6 +77,7 @@ public:
QOpcUaAuthenticationInformation authenticationInformation() const;
Q_INVOKABLE bool readNodeAttributes(const QJSValue &value);
+ Q_INVOKABLE bool writeNodeAttributes(const QJSValue &value);
QStringList supportedSecurityPolicies() const;
QJSValue supportedUserTokenTypes() const;
@@ -94,10 +95,12 @@ signals:
void defaultConnectionChanged();
void namespacesChanged();
void readNodeAttributesFinished(const QVariant &value);
+ void writeNodeAttributesFinished(const QVariant &value);
private slots:
void clientStateHandler(QOpcUaClient::ClientState state);
void handleReadNodeAttributesFinished(const QVector<QOpcUaReadResult> &results);
+ void handleWriteNodeAttributesFinished(const QVector<QOpcUaWriteResult> &results);
private:
QOpcUaClient *m_client = nullptr;
diff --git a/src/imports/opcua/opcuawriteitem.cpp b/src/imports/opcua/opcuawriteitem.cpp
new file mode 100644
index 0000000..b86e0f9
--- /dev/null
+++ b/src/imports/opcua/opcuawriteitem.cpp
@@ -0,0 +1,262 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt OPC UA module.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "opcuawriteitem.h"
+#include "opcuawriteresult.h"
+#include <QJSValue>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \qmltype WriteItem
+ \inqmlmodule QtOpcUa
+ \brief Specifies an item to be written to the server.
+ \since QtOpcUa 5.13
+
+ This type is used to specify items to be written to the server using the function
+ \l Connection::writeNodeAttributes.
+*/
+
+/*!
+ \qmlproperty Constants.NodeAttribute WriteItem::attribute
+
+ Determines the attribute of the node to be written.
+*/
+
+/*!
+ \qmlproperty string WriteItem::indexRange
+
+ Determines the index range of the attribute to be written.
+ If not needed, leave this property empty.
+*/
+
+/*!
+ \qmlproperty string Writetem::nodeId
+
+ Determines the node id of the node to be written.
+*/
+
+/*!
+ \qmlproperty variant WriteItem::ns
+
+ Determines the namespace of the node to be written.
+ The namespace can be given by name or index.
+ If this property is given, any namespace in the node id will be
+ ignored.
+*/
+
+/*!
+ \qmlproperty datetime WriteItem::serverTimestamp
+
+ Sets the server timestamp for the value to be written.
+ If the server timestamp is invalid, it is ignored by the client and not sent to the server.
+ If the server doesn't support writing timestamps, the write operation for this item
+ will fail.
+*/
+
+/*!
+ \qmlproperty datetime WriteItem::sourceTimestamp
+
+ Sets the source timestamp for the value to write.
+ If the source timestamp is invalid, it is ignored by the client and not sent to the server.
+ If the server doesn't support writing timestamps, the write operation for this item
+ will fail.
+*/
+
+/*!
+ \qmlproperty variant WriteItem::value
+
+ Actual data that is requested to be written.
+*/
+
+/*!
+ \qmlproperty variant WriteItem::valueType
+
+ If given, the type information will be used in converting
+ the value to a SDK specific data type.
+*/
+
+/*!
+ \qmlproperty OpcUaStatus WriteItem::statusCode
+
+ Sets the status code for the value to write.
+ If no status code is set, no status code is sent to the server.
+*/
+
+class OpcUaWriteItemData : public QSharedData
+{
+public:
+ QOpcUa::NodeAttribute attribute;
+ QString indexRange;
+ QString nodeId;
+ QVariant namespaceIdentifier;
+ QDateTime serverTimestamp;
+ QDateTime sourceTimestamp;
+ QVariant value;
+ QOpcUa::Types valueType = QOpcUa::Types::Undefined;
+ OpcUaStatus::Status statusCode;
+ bool hasStatusCode = false;
+};
+
+OpcUaWriteItem::OpcUaWriteItem()
+ : data(new OpcUaWriteItemData)
+{
+ data->attribute = QOpcUa::NodeAttribute::Value;
+}
+
+OpcUaWriteItem::OpcUaWriteItem(const OpcUaWriteItem &other)
+ : data(other.data)
+{
+}
+
+OpcUaWriteItem &OpcUaWriteItem::operator=(const OpcUaWriteItem &rhs)
+{
+ if (this != &rhs)
+ data.operator=(rhs.data);
+ return *this;
+}
+
+OpcUaWriteItem::~OpcUaWriteItem() = default;
+
+const QString &OpcUaWriteItem::indexRange() const
+{
+ return data->indexRange;
+}
+
+void OpcUaWriteItem::setIndexRange(const QString &indexRange)
+{
+ data->indexRange = indexRange;
+}
+
+const QString &OpcUaWriteItem::nodeId() const
+{
+ return data->nodeId;
+}
+
+void OpcUaWriteItem::setNodeId(const QString &nodeId)
+{
+ data->nodeId = nodeId;
+}
+
+QOpcUa::NodeAttribute OpcUaWriteItem::attribute() const
+{
+ return data->attribute;
+}
+
+void OpcUaWriteItem::setAttribute(QOpcUa::NodeAttribute attribute)
+{
+ data->attribute = attribute;
+}
+
+const QVariant &OpcUaWriteItem::namespaceIdentifier() const
+{
+ return data->namespaceIdentifier;
+}
+
+void OpcUaWriteItem::setNamespaceIdentifier(const QVariant &namespaceIdentifier)
+{
+ data->namespaceIdentifier = namespaceIdentifier;
+}
+
+void OpcUaWriteItem::setServerTimestamp(const QDateTime &serverTimestamp)
+{
+ data->serverTimestamp = serverTimestamp;
+}
+
+const QDateTime &OpcUaWriteItem::serverTimestamp() const
+{
+ return data->serverTimestamp;
+}
+
+void OpcUaWriteItem::setSourceTimestamp(const QDateTime &sourceTimestamp)
+{
+ data->sourceTimestamp = sourceTimestamp;
+}
+
+const QDateTime &OpcUaWriteItem::sourceTimestamp() const
+{
+ return data->sourceTimestamp;
+}
+
+void OpcUaWriteItem::setValue(const QVariant &value)
+{
+ auto tmp = value;
+ // In case of an array value the type is QJSValue,
+ // which has to be unpacked to recognized.
+ if (tmp.userType() == qMetaTypeId<QJSValue>())
+ tmp = tmp.value<QJSValue>().toVariant();
+
+ data->value = tmp;
+}
+
+const QVariant &OpcUaWriteItem::value() const
+{
+ return data->value;
+}
+
+QOpcUa::Types OpcUaWriteItem::valueType() const
+{
+ return data->valueType;
+}
+
+void OpcUaWriteItem::setValueType(QOpcUa::Types type)
+{
+ data->valueType = type;
+}
+
+OpcUaStatus::Status OpcUaWriteItem::statusCode() const
+{
+ return data->statusCode;
+}
+
+bool OpcUaWriteItem::hasStatusCode() const
+{
+ return data->hasStatusCode;
+}
+
+void OpcUaWriteItem::setStatusCode(OpcUaStatus::Status statusCode)
+{
+ data->statusCode = statusCode;
+ data->hasStatusCode = true;
+}
+
+OpcUaWriteItem OpcUaWriteItemFactory::create()
+{
+ return OpcUaWriteItem();
+}
+
+QT_END_NAMESPACE
+
diff --git a/src/imports/opcua/opcuawriteitem.h b/src/imports/opcua/opcuawriteitem.h
new file mode 100644
index 0000000..d238c61
--- /dev/null
+++ b/src/imports/opcua/opcuawriteitem.h
@@ -0,0 +1,109 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt OPC UA module.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef OPCUAWRITEITEM_H
+#define OPCUAWRITEITEM_H
+
+#include <QObject>
+#include <QDateTime>
+#include <QtCore/qshareddata.h>
+#include "opcuastatus.h"
+#include "qopcuatype.h"
+
+QT_BEGIN_NAMESPACE
+
+class OpcUaWriteItemData;
+class OpcUaWriteItem
+{
+ Q_GADGET
+ Q_PROPERTY(QString nodeId READ nodeId WRITE setNodeId)
+ Q_PROPERTY(QVariant ns READ namespaceIdentifier WRITE setNamespaceIdentifier)
+ Q_PROPERTY(QOpcUa::NodeAttribute attribute READ attribute WRITE setAttribute)
+ Q_PROPERTY(QString indexRange READ indexRange WRITE setIndexRange)
+ Q_PROPERTY(QVariant value READ value WRITE setValue)
+ Q_PROPERTY(QOpcUa::Types valueType READ valueType WRITE setValueType)
+ Q_PROPERTY(QDateTime sourceTimestamp READ sourceTimestamp WRITE setSourceTimestamp)
+ Q_PROPERTY(QDateTime serverTimestamp READ serverTimestamp WRITE setServerTimestamp)
+ Q_PROPERTY(OpcUaStatus::Status statusCode READ statusCode WRITE setStatusCode)
+
+public:
+ OpcUaWriteItem();
+ OpcUaWriteItem(const OpcUaWriteItem &other);
+ OpcUaWriteItem &operator=(const OpcUaWriteItem &rhs);
+ ~OpcUaWriteItem();
+
+ const QString &nodeId() const;
+ void setNodeId(const QString &nodeId);
+
+ const QVariant &namespaceIdentifier() const;
+ void setNamespaceIdentifier(const QVariant &namespaceIdentifier);
+
+ QOpcUa::NodeAttribute attribute() const;
+ void setAttribute(QOpcUa::NodeAttribute attribute);
+
+ const QString &indexRange() const;
+ void setIndexRange(const QString &indexRange);
+
+ const QVariant &value() const;
+ void setValue(const QVariant &value);
+
+ QOpcUa::Types valueType() const;
+ void setValueType(QOpcUa::Types type);
+
+ const QDateTime &sourceTimestamp() const;
+ void setSourceTimestamp(const QDateTime &sourceTimestamp);
+
+ const QDateTime &serverTimestamp() const;
+ void setServerTimestamp(const QDateTime &serverTimestamp);
+
+ OpcUaStatus::Status statusCode() const;
+ bool hasStatusCode() const;
+ void setStatusCode(OpcUaStatus::Status statusCode);
+
+private:
+ QSharedDataPointer<OpcUaWriteItemData> data;
+};
+
+class OpcUaWriteItemFactory : public QObject
+{
+ Q_OBJECT
+public:
+ Q_INVOKABLE OpcUaWriteItem create();
+};
+
+QT_END_NAMESPACE
+
+#endif // OPCUAWRITEITEM_H
diff --git a/src/imports/opcua/opcuawriteresult.cpp b/src/imports/opcua/opcuawriteresult.cpp
new file mode 100644
index 0000000..6e75ed8
--- /dev/null
+++ b/src/imports/opcua/opcuawriteresult.cpp
@@ -0,0 +1,161 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt OPC UA module.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "opcuawriteresult.h"
+#include "universalnode.h"
+#include <QOpcUaWriteResult>
+#include <QOpcUaClient>
+#include <qopcuatype.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \qmltype WriteResult
+ \inqmlmodule QtOpcUa
+ \brief Contains result data after writing to the server.
+ \since QtOpcUa 5.13
+
+ This type is used to pass the results after writing to the server using the function
+ \l Connection::writeNodeAttributes.
+
+ \sa WriteItem
+*/
+
+/*!
+ \qmlproperty Constants.NodeAttribute WriteResult::attribute
+ \readonly
+
+ The node attribute of data that was written.
+*/
+
+/*!
+ \qmlproperty string WriteResult::indexRange
+ \readonly
+
+ The index range of the data that was written.
+*/
+
+/*!
+ \qmlproperty string WriteResult::nodeId
+ \readonly
+
+ The node id of the node that was written.
+*/
+
+/*!
+ \qmlproperty string WriteResult::namespaceName
+ \readonly
+
+ The namespace name of the node that was written.
+*/
+
+/*!
+ \qmlproperty Status WriteResult::status
+ \readonly
+
+ Result status of this WriteResult.
+ If the write request was successful the status is \l Status.Good.
+*/
+
+class OpcUaWriteResultData : public QSharedData
+{
+public:
+ OpcUaStatus status;
+ QOpcUa::NodeAttribute attribute;
+ QString indexRange;
+ QString nodeId;
+ QString namespaceName;
+};
+
+OpcUaWriteResult::OpcUaWriteResult()
+ : data(new OpcUaWriteResultData)
+{
+ data->attribute = QOpcUa::NodeAttribute::None;
+}
+
+OpcUaWriteResult::OpcUaWriteResult(const OpcUaWriteResult &other)
+ : data(other.data)
+{
+}
+
+OpcUaWriteResult::OpcUaWriteResult(const QOpcUaWriteResult &other, const QOpcUaClient *client)
+ : data(new OpcUaWriteResultData)
+{
+ data->status = OpcUaStatus(other.statusCode());
+ data->attribute = other.attribute();
+ data->indexRange = other.indexRange();
+
+ int namespaceIndex = -1;
+ UniversalNode::splitNodeIdAndNamespace(other.nodeId(), &namespaceIndex, &data->nodeId);
+ data->namespaceName = client->namespaceArray().at(namespaceIndex);
+}
+
+OpcUaWriteResult &OpcUaWriteResult::operator=(const OpcUaWriteResult &rhs)
+{
+ if (this != &rhs)
+ data.operator=(rhs.data);
+ return *this;
+}
+
+OpcUaWriteResult::~OpcUaWriteResult() = default;
+
+const QString &OpcUaWriteResult::indexRange() const
+{
+ return data->indexRange;
+}
+
+const QString &OpcUaWriteResult::nodeId() const
+{
+ return data->nodeId;
+}
+
+QOpcUa::NodeAttribute OpcUaWriteResult::attribute() const
+{
+ return data->attribute;
+}
+
+const QString &OpcUaWriteResult::namespaceName() const
+{
+ return data->namespaceName;
+}
+
+OpcUaStatus OpcUaWriteResult::status() const
+{
+ return data->status;
+}
+
+QT_END_NAMESPACE
+
diff --git a/src/imports/opcua/opcuawriteresult.h b/src/imports/opcua/opcuawriteresult.h
new file mode 100644
index 0000000..d34e95b
--- /dev/null
+++ b/src/imports/opcua/opcuawriteresult.h
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt OPC UA module.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef OPCUAWRITERESULT_H
+#define OPCUAWRITERESULT_H
+
+#include <QObject>
+#include <QDateTime>
+#include "qopcuatype.h"
+#include "opcuastatus.h"
+
+QT_BEGIN_NAMESPACE
+
+class QOpcUaWriteResult;
+class QOpcUaClient;
+class OpcUaWriteResultData;
+class OpcUaWriteResult
+{
+ Q_GADGET
+ Q_PROPERTY(QOpcUa::NodeAttribute attribute READ attribute)
+ Q_PROPERTY(QString indexRange READ indexRange)
+ Q_PROPERTY(QString nodeId READ nodeId)
+ Q_PROPERTY(QString namespaceName READ namespaceName)
+ Q_PROPERTY(OpcUaStatus status READ status)
+
+public:
+ OpcUaWriteResult();
+ OpcUaWriteResult(const OpcUaWriteResult &other);
+ OpcUaWriteResult(const QOpcUaWriteResult &other, const QOpcUaClient *client);
+ OpcUaWriteResult &operator=(const OpcUaWriteResult &rhs);
+ ~OpcUaWriteResult();
+
+ const QString &indexRange() const;
+ const QString &nodeId() const;
+ QOpcUa::NodeAttribute attribute() const;
+ const QString &namespaceName() const;
+
+ OpcUaStatus status() const;
+
+private:
+ QSharedDataPointer<OpcUaWriteResultData> data;
+};
+
+
+QT_END_NAMESPACE
+
+Q_DECLARE_METATYPE(OpcUaWriteResult)
+
+#endif // OPCUAWRITERESULT_H
diff --git a/tests/auto/declarative/BatchReadTest.qml b/tests/auto/declarative/BatchReadWriteTest.qml
index 2e0f99b..52d33aa 100644
--- a/tests/auto/declarative/BatchReadTest.qml
+++ b/tests/auto/declarative/BatchReadWriteTest.qml
@@ -142,4 +142,105 @@ Item {
compare(results[2].value, [1, 2]);
}
}
+
+ CompletionLoggingTestCase {
+ name: "Writing multiple items"
+ when: connection.connected && shouldRun
+
+ SignalSpy {
+ id: writeNodeAttributesFinishedSpy
+ target: connection
+ signalName: "writeNodeAttributesFinished"
+ }
+
+ function test_nodeTest() {
+ var writeItemList = [];
+ var writeItem;
+
+ // Item #0
+ writeItem = QtOpcUa.WriteItem.create();
+ writeItem.ns = "http://qt-project.org";
+ writeItem.nodeId = "s=Demo.Static.Scalar.String";
+ writeItem.attribute = QtOpcUa.Constants.NodeAttribute.Value;
+ writeItem.value = "Writing multiple items";
+ writeItemList.push(writeItem);
+
+ // Item #1
+ writeItem = QtOpcUa.WriteItem.create();
+ writeItem.ns = "http://qt-project.org";
+ writeItem.nodeId = "s=Demo.Static.Scalar.Double";
+ writeItem.value = 15.6;
+ writeItemList.push(writeItem);
+
+ // Item #2
+ writeItem = QtOpcUa.WriteItem.create();
+ writeItem.ns = "http://qt-project.org";
+ writeItem.nodeId = "s=Demo.Static.Arrays.UInt32";
+ writeItem.indexRange = "0:1";
+ writeItem.value = [42, 43];
+ writeItem.valueType = QtOpcUa.Constants.UInt32;
+ writeItemList.push(writeItem);
+
+ verify(connection.writeNodeAttributes(writeItemList))
+ writeNodeAttributesFinishedSpy.wait();
+
+ compare(writeNodeAttributesFinishedSpy.count, 1);
+ compare(writeNodeAttributesFinishedSpy.signalArguments[0].length, 1);
+
+ var results = writeNodeAttributesFinishedSpy.signalArguments[0][0];
+
+ compare(results.length, writeItemList.length);
+ for (var i = 0; i < results.length; i++) {
+ console.log("Comparing result item #" + i);
+ verify(results[i].status.isGood);
+ compare(results[i].nodeId, writeItemList[i].nodeId);
+ compare(results[i].namespaceName, writeItemList[i].ns);
+ compare(results[i].attribute, writeItemList[i].attribute);
+ }
+
+ // Reset to default values
+ //
+ writeItemList = [];
+ // Item #0
+ writeItem = QtOpcUa.WriteItem.create();
+ writeItem.ns = "http://qt-project.org";
+ writeItem.nodeId = "s=Demo.Static.Scalar.String";
+ writeItem.attribute = QtOpcUa.Constants.NodeAttribute.Value;
+ writeItem.value = "Value";
+ writeItemList.push(writeItem);
+
+ // Item #1
+ writeItem = QtOpcUa.WriteItem.create();
+ writeItem.ns = "http://qt-project.org";
+ writeItem.nodeId = "s=Demo.Static.Scalar.Double";
+ writeItem.value = 1.0;
+ writeItem.valueType = QtOpcUa.Constants.Double;
+ writeItemList.push(writeItem);
+
+ // Item #2
+ writeItem = QtOpcUa.WriteItem.create();
+ writeItem.ns = "http://qt-project.org";
+ writeItem.nodeId = "s=Demo.Static.Arrays.UInt32";
+ writeItem.indexRange = "0:1";
+ writeItem.value = [1, 2];
+ writeItem.valueType = QtOpcUa.Constants.UInt32;
+ writeItemList.push(writeItem);
+
+ writeNodeAttributesFinishedSpy.clear();
+ verify(connection.writeNodeAttributes(writeItemList))
+ writeNodeAttributesFinishedSpy.wait();
+
+ var results = writeNodeAttributesFinishedSpy.signalArguments[0][0];
+
+ compare(results.length, writeItemList.length);
+ for (var i = 0; i < results.length; i++) {
+ console.log("Comparing result item #" + i);
+ verify(results[i].status.isGood);
+ compare(results[i].nodeId, writeItemList[i].nodeId);
+ compare(results[i].namespaceName, writeItemList[i].ns);
+ compare(results[i].attribute, writeItemList[i].attribute);
+ }
+
+ }
+ }
}
diff --git a/tests/auto/declarative/tst_batchReadWrite.qml b/tests/auto/declarative/tst_batchReadWrite.qml
new file mode 100644
index 0000000..2a0a2a8
--- /dev/null
+++ b/tests/auto/declarative/tst_batchReadWrite.qml
@@ -0,0 +1,41 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt OPC UA module.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.3
+
+BackendTestMultiplier {
+ testName: "BatchReadWriteTest"
+}