Can't connect to PLC via Qt Opc UA module
-
Goodday, everyone!
I need your help. I need to write a C++ program that can get and set values from/to variables of the program run on a PLC.
The manufaturer of the PLC told me they use Modbus RTU and OPC UA data transfer protocols to connect it to PLC programming software CODESYS. The data I need to change is transferred via OPC UA so I built QtOpcUa module (https://doc.qt.io/qt-5/qtopcua-index.html) and added it to my project. I studied these examples of how to make a client: https://doc.qt.io/qt-5/qtopcua-examples.html. The three programs from here (client, server, viewer) all work great but when I tried to change example server's IP to my PLC's IP QtCreator failed to succeed. What's more: this viewer also failed to get a tree of nodes from PLC's loaded program.However, when I tried to use another software developer's OPC UA client UaExpert (https://www.unified-automation.com/downloads/opc-ua-clients.html) it read nodes of both the example server and my PLC. So its values can be read and changed dynamically what I found out using it. I just don't understand why that first client can't see it as well as my program based entirely on the client example?
-
@kyakovlev said in Can't connect to PLC via Qt Opc UA module:
QtCreator failed to succeed
In what way?
-
@jsulm
This is a console log of the successfull connection to server-local example provided by the developer of the Ot OPC UA module:10:22:00: Starting C:\Users\Admin\Documents\build-Project3-4-Desktop_Qt_5_15_2_MinGW_64_bit-Debug\debug\Project3-4.exe... [2024-03-14 10:22:01.566 (UTC+0300)] info/client SecurityPolicy not specified -> use default #None [2024-03-14 10:22:01.566 (UTC+0300)] warn/securitypolicy Security policy None is used to create SecureChannel. Accepting all certificates [2024-03-14 10:22:01.569 (UTC+0300)] info/client TCP connection established [2024-03-14 10:22:01.571 (UTC+0300)] info/client Opened SecureChannel with SecurityPolicy http://opcfoundation.org/UA/SecurityPolicy#None [2024-03-14 10:22:01.854 (UTC+0300)] info/client Connecting to endpoint opc.tcp://127.0.0.1:43344 [2024-03-14 10:22:01.854 (UTC+0300)] info/client SecurityPolicy not specified -> use default #None [2024-03-14 10:22:01.854 (UTC+0300)] warn/securitypolicy Security policy None is used to create SecureChannel. Accepting all certificates [2024-03-14 10:22:01.854 (UTC+0300)] info/client TCP connection established [2024-03-14 10:22:01.855 (UTC+0300)] info/client Opened SecureChannel with SecurityPolicy http://opcfoundation.org/UA/SecurityPolicy#None [2024-03-14 10:22:01.855 (UTC+0300)] info/client Endpoint and UserTokenPolicy unconfigured, perform GetEndpoints [2024-03-14 10:22:01.856 (UTC+0300)] info/client Found 1 endpoints [2024-03-14 10:22:01.856 (UTC+0300)] info/client Endpoint 0 has 2 user token policies [2024-03-14 10:22:01.856 (UTC+0300)] info/client Selected Endpoint opc.tcp://127.0.0.1:43344 with SecurityMode None and SecurityPolicy http://opcfoundation.org/UA/SecurityPolicy#None [2024-03-14 10:22:01.856 (UTC+0300)] info/client Selected UserTokenPolicy open62541-anonymous-policy with UserTokenType Anonymous and SecurityPolicy http://opcfoundation.org/UA/SecurityPolicy#None Monitoring successfully enabled for "ns=2;s=Machine.Tank2.TargetPercent"
And this is a console log of the failed attempt to connect to the PLC:
10:23:33: Starting C:\Users\Admin\Documents\build-Project3-4-Desktop_Qt_5_15_2_MinGW_64_bit-Debug\debug\Project3-4.exe... [2024-03-14 10:23:34.712 (UTC+0300)] info/client SecurityPolicy not specified -> use default #None [2024-03-14 10:23:34.712 (UTC+0300)] warn/securitypolicy Security policy None is used to create SecureChannel. Accepting all certificates [2024-03-14 10:23:34.716 (UTC+0300)] info/client TCP connection established [2024-03-14 10:23:34.724 (UTC+0300)] info/client Opened SecureChannel with SecurityPolicy http://opcfoundation.org/UA/SecurityPolicy#None [2024-03-14 10:23:35.068 (UTC+0300)] info/client Connecting to endpoint opc.tcp://plc210:4840 [2024-03-14 10:23:35.068 (UTC+0300)] info/client SecurityPolicy not specified -> use default #None [2024-03-14 10:23:35.068 (UTC+0300)] warn/securitypolicy Security policy None is used to create SecureChannel. Accepting all certificates qt.opcua.plugins.open62541: Open62541: Failed to connect [2024-03-14 10:23:41.383 (UTC+0300)] warn/network Trying to connect to opc.tcp://plc210:4840 timed out [2024-03-14 10:23:41.383 (UTC+0300)] error/client Opening the TCP socket failed [2024-03-14 10:23:41.383 (UTC+0300)] error/client Couldn't connect the client to a TCP secure channel
And the only thing I changed in my code was changing these two lines of code in my programm:
uaBackend.connectToEndpoint("opc.tcp://127.0.0.1:43344", 0);
for
uaBackend.connectToEndpoint("opc.tcp://192.168.0.10:4840", 0);
And
m_valueAAAAAANode.reset(m_client->node("ns=2;s=Machine.Tank2.TargetPercent"));
to
m_valueAAAAAANode.reset(m_client->node("ns=4;s=|var|PLC210 OPC-UA.Application.MainPRG.lrAAAAAA"));