Solved OPC UA node huge list read/subscribe
-
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?
-
@Merlino
Maybe I misunderstand. ButtestNode
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? -
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? });
-
@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...
-
@Merlino said in OPC UA node huge list read/subscribe:
but written like this I doubt it will work
Why not? Did you try?
-
@jsulm yes, it works! :)