Can't connect to PLC via Qt Opc UA module|OPC UA Implementation: Stacks, Tools, and Samples|Forum|OPC Foundation

Avatar
Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
Lost password?
sp_Feed sp_PrintTopic sp_TopicIcon
Can't connect to PLC via Qt Opc UA module
Avatar
Konstantin Yakovlev
Member
Members
Forum Posts: 3
Member Since:
03/13/2024
sp_UserOfflineSmall Offline
1
03/13/2024 - 23:35
sp_Permalink sp_Print sp_EditHistory

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.....mples.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.....ients.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?

Avatar
Randy Armstrong
Admin
Forum Posts: 1451
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
2
03/14/2024 - 19:40
sp_Permalink sp_Print

This is usually a sign that you are not providing the correct information to CreateSession and ActivateSession.

You should check for error codes being returned from these calls.

Avatar
Konstantin Yakovlev
Member
Members
Forum Posts: 3
Member Since:
03/13/2024
sp_UserOfflineSmall Offline
3
03/15/2024 - 01:42
sp_Permalink sp_Print

I'm not quite sure where to find status info about CreateSession and ActivateSession. Should it be written in the console output? Then there's no mentions of it when I launch the viewer and try to connect to my PLC:

 

11:32:07: Starting C:\Qt\5.15.2\mingw81_64\qtopcua\examples\opcua\opcuaviewer\debug\opcuaviewer.exe...
Creating PKI path 'C:/Qt/5.15.2/mingw81_64/qtopcua/examples/opcua/opcuaviewer/debug..//pki/trusted/certs': FAILED.
qt.opcua.security: No client certificate found at "C:/Qt/5.15.2/mingw81_64/qtopcua/examples/opcua/opcuaviewer/debug..//pki/own/certs/opcuaviewer.der" . Application identity will be invalid.
Discovering servers on "opc.tcp://192.168.0.10:4840"
[2024-03-15 11:32:22.543 (UTC+0300)] info/client SecurityPolicy not specified -> use default #None
[2024-03-15 11:32:22.543 (UTC+0300)] warn/securitypolicy Security policy None is used to create SecureChannel. Accepting all certificates
[2024-03-15 11:32:22.546 (UTC+0300)] info/client TCP connection established
[2024-03-15 11:32:22.554 (UTC+0300)] info/client Opened SecureChannel with SecurityPolicy https://opcfoundation.org/UA/SecurityPolicy#None
Failed to retrive endpoints from with status BadConnectionClosed
[2024-03-15 11:32:25.871 (UTC+0300)] info/client SecurityPolicy not specified -> use default #None
[2024-03-15 11:32:25.871 (UTC+0300)] warn/securitypolicy Security policy None is used to create SecureChannel. Accepting all certificates
[2024-03-15 11:32:25.871 (UTC+0300)] warn/network Server url is invalid:
[2024-03-15 11:32:25.871 (UTC+0300)] error/client Opening the TCP socket failed

Screenshot:

View post on imgur.com

 

And this is the console log I get when successfully connecting to the example sever:

11:38:26: Starting C:\Qt\5.15.2\mingw81_64\qtopcua\examples\opcua\opcuaviewer\debug\opcuaviewer.exe...
Creating PKI path 'C:/Qt/5.15.2/mingw81_64/qtopcua/examples/opcua/opcuaviewer/debug..//pki/trusted/certs': FAILED.
qt.opcua.security: No client certificate found at "C:/Qt/5.15.2/mingw81_64/qtopcua/examples/opcua/opcuaviewer/debug..//pki/own/certs/opcuaviewer.der" . Application identity will be invalid.
Discovering servers on "opc.tcp://127.0.0.1:43344"
[2024-03-15 11:38:37.872 (UTC+0300)] info/client SecurityPolicy not specified -> use default #None
[2024-03-15 11:38:37.872 (UTC+0300)] warn/securitypolicy Security policy None is used to create SecureChannel. Accepting all certificates
[2024-03-15 11:38:37.874 (UTC+0300)] info/client TCP connection established
[2024-03-15 11:38:37.874 (UTC+0300)] info/client Opened SecureChannel with SecurityPolicy https://opcfoundation.org/UA/SecurityPolicy#None
[2024-03-15 11:38:40.207 (UTC+0300)] info/client SecurityPolicy not specified -> use default #None
[2024-03-15 11:38:40.207 (UTC+0300)] warn/securitypolicy Security policy None is used to create SecureChannel. Accepting all certificates
[2024-03-15 11:38:40.211 (UTC+0300)] info/client TCP connection established
[2024-03-15 11:38:40.212 (UTC+0300)] info/client Opened SecureChannel with SecurityPolicy https://opcfoundation.org/UA/SecurityPolicy#None
Client state changed QOpcUaClient::Connecting
[2024-03-15 11:38:42.359 (UTC+0300)] info/client Connecting to endpoint opc.tcp://nf-99-83:43344/
[2024-03-15 11:38:42.359 (UTC+0300)] info/client SecurityPolicy not specified -> use default #None
[2024-03-15 11:38:42.359 (UTC+0300)] warn/securitypolicy Security policy None is used to create SecureChannel. Accepting all certificates
[2024-03-15 11:38:42.359 (UTC+0300)] info/client TCP connection established
[2024-03-15 11:38:42.361 (UTC+0300)] info/client Opened SecureChannel with SecurityPolicy https://opcfoundation.org/UA/SecurityPolicy#None
[2024-03-15 11:38:42.361 (UTC+0300)] info/client Endpoint and UserTokenPolicy unconfigured, perform GetEndpoints
[2024-03-15 11:38:42.361 (UTC+0300)] info/client Found 1 endpoints
[2024-03-15 11:38:42.361 (UTC+0300)] info/client Endpoint 0 has 2 user token policies
[2024-03-15 11:38:42.361 (UTC+0300)] info/client Selected Endpoint opc.tcp://nf-99-83:43344/ with SecurityMode None and SecurityPolicy https://opcfoundation.org/UA/SecurityPolicy#None
[2024-03-15 11:38:42.361 (UTC+0300)] info/client Selected UserTokenPolicy open62541-anonymous-policy with UserTokenType Anonymous and SecurityPolicy https://opcfoundation.org/UA/SecurityPolicy#None
Client state changed QOpcUaClient::Connected

Screenshot:

View post on imgur.com

Avatar
Randy Armstrong
Admin
Forum Posts: 1451
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
4
03/15/2024 - 21:00
sp_Permalink sp_Print

This is the problem:

[2024-03-15 11:32:25.871 (UTC+0300)] warn/network Server url is invalid:

It is not clear what is being called the "Server url". Find where that error is coming from an figure out if a field is null when it should have a valid URL.

Avatar
Konstantin Yakovlev
Member
Members
Forum Posts: 3
Member Since:
03/13/2024
sp_UserOfflineSmall Offline
5
03/17/2024 - 23:15
sp_Permalink sp_Print

Well, yes, it is null. At least very likely to be so: the third dropdown in the first picture shows empty space after pushing "Find Servers" button. When in the second pic it catches the IP of the computer with a local process with server-example running and changes it to the name of the computer "nf-99-83". I don't understand why the third dropdown is empty when I'm connecting to the PLC launched as a OPC UA server while not empty when connecting to the computer process with this server-example.

Avatar
Randy Armstrong
Admin
Forum Posts: 1451
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
6
03/18/2024 - 02:26
sp_Permalink sp_Print sp_EditHistory

You need to look at what is coming back from the FindServers and GetEndpoints calls.

These results are being used to populate the dialog.

A common problem for clients is they do not have DNS configured so the domain name in the URL cannot be used.

Clients are expected to replace the domain in the URL with a domain/ip address that is known to work before connecting.

This should produce a domain mismatch error which has to be ignored when DNS is not functional on a network.

In a production system you need to configure servers to use the IP and not the hostname if there is no DNS or enable a DNS.

Forum Timezone: America/Phoenix
Most Users Ever Online: 510
Currently Online:
Guest(s) 18
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Forum Stats:
Groups: 2
Forums: 10
Topics: 1351
Posts: 4579