Details
-
Bug
-
Resolution: Fixed
-
P3: Somewhat important
-
6.6.3
-
Windows 10 22H2, Python 3.11
-
12744e330 (tqtc/dev), b7d62470a (tqtc/6.7.0), 142b02fd6 (tqtc/6.7)
Description
This issue seems similar to PYSIDE-1824
Code
Attached is a modifed version of the official OpcUa Viewer Example (https://doc.qt.io/qtforpython-6/examples/example_opcua_opcuaviewer.html ) where mainwindow.py was modified to call QOpcUaClient.readNodeAttributes(). The subsequent QOpcUaClient.readNodeAttributesFinished() signal is connected to a new slot called "onReadNodeAttributesFinished":
# === THE FIRST FEW LINES ARE FROM THE EXAMPLE === @Slot() def clientConnected(self): self._client_connected = True self.updateUiState() self._opcua_client.namespaceArrayUpdated.connect(self.namespacesArrayUpdated) self._opcua_client.updateNamespaceArray() # === NEW LINES ADDED BELOW HERE === # This works out-of-the-box with the OPC UA C++ Demo Server (https://www.unified-automation.com/downloads/opc-ua-servers.html ). # If using a different server, replace the request ID with a valid node on your server. self._opcua_client.readNodeAttributesFinished.connect(self.onReadNodeAttributesFinished) request = [QOpcUaReadItem("ns=3;s=AirConditioner_1.Temperature")] self._opcua_client.readNodeAttributes(request) @Slot(list, QOpcUa.UaStatusCode) def onReadNodeAttributesFinished(self, results, serviceResult): print("Node attributes read. State: {} Result: {}".format(serviceResult, results)) for result in results: if isinstance(result, QOpcUaReadResult): print("{}: {} ({})".format( result.nodeId(), result.value(), result.attribute()))
Steps to reproduce
- Run your OPC UA server
- Load the attached example
- Ensure that OpenSSL is available in the PATH (required to load the "open62541" plugin)
- Run the example and connect to your server
(Unfortunately, a real OPC UA server is required to trigger the QOpcUaClient.readNodeAttributesFinished() signal - manually emitting this using Python-constructed objects doesn't work)
Outcomes
C:\Qt\QtForPython\6.6.3\Src\examples\opcua\opcuaviewer\main.py:19: RuntimeWarning: CopyCppToPython(): SbkConverter::copyToPython is null for "PySide6.QtOpcUa.QOpcUaReadResult". sys.exit(app.exec()) Node attributes read. State: UaStatusCode.Good Result: [None]
Note: We expect the Result list to contain a PySide6.QtOpcUa.QOpcUaReadResult object instead of None
[signal] void QOpcUaClient::readNodeAttributesFinished(QList<QOpcUaReadResult> results, QOpcUa::UaStatusCode serviceResult)