Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can't connect to PLC via Qt Opc UA module
Forum Updated to NodeBB v4.3 + New Features

Can't connect to PLC via Qt Opc UA module

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt6.6opcuaopc client
4 Posts 2 Posters 827 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kyakovlev
    wrote on 13 Mar 2024, 11:00 last edited by
    #1

    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?

    J 1 Reply Last reply 14 Mar 2024, 06:56
    0
    • K kyakovlev
      13 Mar 2024, 11:00

      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?

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 14 Mar 2024, 06:56 last edited by
      #2

      @kyakovlev said in Can't connect to PLC via Qt Opc UA module:

      QtCreator failed to succeed

      In what way?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      K 1 Reply Last reply 14 Mar 2024, 07:33
      0
      • J jsulm
        14 Mar 2024, 06:56

        @kyakovlev said in Can't connect to PLC via Qt Opc UA module:

        QtCreator failed to succeed

        In what way?

        K Offline
        K Offline
        kyakovlev
        wrote on 14 Mar 2024, 07:33 last edited by
        #3

        @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"));
        
        1 Reply Last reply
        0
        • K Offline
          K Offline
          kyakovlev
          wrote on 19 Mar 2024, 08:58 last edited by
          #4

          No ideas at all..?

          1 Reply Last reply
          0

          4/4

          19 Mar 2024, 08:58

          • Login

          • Login or register to search.
          4 out of 4
          • First post
            4/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved