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. OPC UA node huge list read/subscribe
Forum Updated to NodeBB v4.3 + New Features

OPC UA node huge list read/subscribe

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 536 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.
  • M Offline
    M Offline
    Merlino
    wrote on last edited by Merlino
    #1

    Hello!

    I am developing an application that has to monitor the value changes of a huge list of Opc Ua nodes.

    I have already made a tiny test that works correctly:

    auto* testNode = m_client->node("ns=3;i=1001");
    
    if (testNode)
    {
      connect(testNode, &QOpcUaNode::dataChangeOccurred, this, [](QOpcUa::NodeAttribute attribute, QVariant value)
      {
        // How can I retrieve the nodeId of who generated the event here?
        qInfo().nospace().noquote() << "Attribute " << attribute << " changed " << value ;
      });
    
      m_testNode->enableMonitoring(QOpcUa::NodeAttribute::Value, QOpcUaMonitoringParameters(100));
    }
    

    In this case, however, it is necessary to have a unique slot / lambda for each node. Instead, I would like to focus the management of all changes on a single slot for all monitored nodes.

    The problem is that the "dataChangeOccurred" event does not provide information on the node that raised it.

    Having a single slot for all nodes: how could I know who generated the event?

    JonBJ 1 Reply Last reply
    0
    • M Merlino

      Hello!

      I am developing an application that has to monitor the value changes of a huge list of Opc Ua nodes.

      I have already made a tiny test that works correctly:

      auto* testNode = m_client->node("ns=3;i=1001");
      
      if (testNode)
      {
        connect(testNode, &QOpcUaNode::dataChangeOccurred, this, [](QOpcUa::NodeAttribute attribute, QVariant value)
        {
          // How can I retrieve the nodeId of who generated the event here?
          qInfo().nospace().noquote() << "Attribute " << attribute << " changed " << value ;
        });
      
        m_testNode->enableMonitoring(QOpcUa::NodeAttribute::Value, QOpcUaMonitoringParameters(100));
      }
      

      In this case, however, it is necessary to have a unique slot / lambda for each node. Instead, I would like to focus the management of all changes on a single slot for all monitored nodes.

      The problem is that the "dataChangeOccurred" event does not provide information on the node that raised it.

      Having a single slot for all nodes: how could I know who generated the event?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Merlino
      Maybe I misunderstand. But testNode is the one which emitted the signal, so why don't you pass that to your lambda? Is that not what you are asking for?

      M 1 Reply Last reply
      2
      • fcarneyF Offline
        fcarneyF Offline
        fcarney
        wrote on last edited by
        #3
        connect(testNode, &QOpcUaNode::dataChangeOccurred, this, [testNode](QOpcUa::NodeAttribute attribute, QVariant value)
          {
            // How can I retrieve the nodeId of who generated the event here?
            qInfo().nospace().noquote() << "Attribute " << attribute << " changed " << value ;
            // do stuff with testNode?
          });
        

        C++ is a perfectly valid school of magic.

        1 Reply Last reply
        0
        • JonBJ JonB

          @Merlino
          Maybe I misunderstand. But testNode is the one which emitted the signal, so why don't you pass that to your lambda? Is that not what you are asking for?

          M Offline
          M Offline
          Merlino
          wrote on last edited by
          #4

          @JonB I would like to do something like this:

          for(auto nodeData : listOfNodesToBeSubsribed )
          {
            auto* node = m_client->node(nodeData.nodeID);
            
            if (node)
            {
              m_subscribedNodesList.insert(node);
            
              connect(node, &QOpcUaNode::dataChangeOccurred, this, [this, nodeData](QOpcUa::NodeAttribute attribute, QVariant value)
              {
            	this->DoStuffWithNode(nodeData, value);
              });
            
              node->enableMonitoring(QOpcUa::NodeAttribute::Value, QOpcUaMonitoringParameters(100));	 
            }
          }
          

          but written like this I doubt it will work...

          jsulmJ 1 Reply Last reply
          0
          • M Merlino

            @JonB I would like to do something like this:

            for(auto nodeData : listOfNodesToBeSubsribed )
            {
              auto* node = m_client->node(nodeData.nodeID);
              
              if (node)
              {
                m_subscribedNodesList.insert(node);
              
                connect(node, &QOpcUaNode::dataChangeOccurred, this, [this, nodeData](QOpcUa::NodeAttribute attribute, QVariant value)
                {
              	this->DoStuffWithNode(nodeData, value);
                });
              
                node->enableMonitoring(QOpcUa::NodeAttribute::Value, QOpcUaMonitoringParameters(100));	 
              }
            }
            

            but written like this I doubt it will work...

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Merlino said in OPC UA node huge list read/subscribe:

            but written like this I doubt it will work

            Why not? Did you try?

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

            M 1 Reply Last reply
            0
            • jsulmJ jsulm

              @Merlino said in OPC UA node huge list read/subscribe:

              but written like this I doubt it will work

              Why not? Did you try?

              M Offline
              M Offline
              Merlino
              wrote on last edited by
              #6

              @jsulm yes, it works! :)

              1 Reply Last reply
              0

              • Login

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