Skip to content

Commit

Permalink
unconditionally show error when monitor item fails
Browse files Browse the repository at this point in the history
  • Loading branch information
dirk-zimoch committed Sep 10, 2024
1 parent 35bc784 commit b63d50c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
19 changes: 9 additions & 10 deletions devOpcuaSup/UaSdk/SubscriptionUaSdk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,20 +212,19 @@ SubscriptionUaSdk::addMonitoredItems ()
std::cout << "Subscription " << name << "@" << psessionuasdk->getName()
<< ": created " << items.size() << " monitored items ("
<< status.toString().toUtf8() << ")" << std::endl;
if (debug >= 5) {
for (i = 0; i < items.size(); i++) {
UaNodeId node(monitoredItemCreateRequests[i].ItemToMonitor.NodeId);
if (OpcUa_IsGood(monitoredItemCreateResults[i].StatusCode))
std::cout << "** Monitored item " << node.toXmlString().toUtf8()
for (i = 0; i < items.size(); i++) {
if (OpcUa_IsGood(monitoredItemCreateResults[i].StatusCode)) {
if (debug >= 5)
std::cout << "** Monitored item " << UaNodeId(monitoredItemCreateRequests[i].ItemToMonitor.NodeId).toXmlString().toUtf8()
<< " succeeded with id " << monitoredItemCreateResults[i].MonitoredItemId
<< " revised sampling interval " << monitoredItemCreateResults[i].RevisedSamplingInterval
<< " revised queue size " << monitoredItemCreateResults[i].RevisedQueueSize
<< std::endl;
else
std::cout << "** Monitored item " << node.toXmlString().toUtf8()
<< " failed with error "
<< UaStatus(monitoredItemCreateResults[i].StatusCode).toString().toUtf8()
<< std::endl;
} else {
errlogPrintf("OPC UA record %s monitored item %s failed with error %s\n",
items[i]->recConnector->getRecordName(),
UaNodeId(monitoredItemCreateRequests[i].ItemToMonitor.NodeId).toXmlString().toUtf8(),
UaStatus(monitoredItemCreateResults[i].StatusCode).toString().toUtf8());
}
}
}
Expand Down
21 changes: 10 additions & 11 deletions devOpcuaSup/open62541/SubscriptionOpen62541.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,27 +174,26 @@ SubscriptionOpen62541::addMonitoredItems ()
}
monitoredItemCreateResult = UA_Client_MonitoredItems_createDataChange(
session.client, subscriptionSettings.subscriptionId, UA_TIMESTAMPSTORETURN_BOTH,
monitoredItemCreateRequest, items[i], [] (UA_Client *client, UA_UInt32 subId, void *subContext,
monitoredItemCreateRequest, it, [] (UA_Client *client, UA_UInt32 subId, void *subContext,
UA_UInt32 monId, void *monContext, UA_DataValue *value) {
static_cast<SubscriptionOpen62541*>(subContext)->
dataChange(monId, *static_cast<ItemOpen62541*>(monContext), value);
}, nullptr /* deleteCallback */);
if (monitoredItemCreateResult.statusCode == UA_STATUSCODE_GOOD) {
items[i]->setRevisedSamplingInterval(monitoredItemCreateResult.revisedSamplingInterval);
items[i]->setRevisedQueueSize(monitoredItemCreateResult.revisedQueueSize);
}
if (debug >= 5) {
if (monitoredItemCreateResult.statusCode == UA_STATUSCODE_GOOD)
it->setRevisedSamplingInterval(monitoredItemCreateResult.revisedSamplingInterval);
it->setRevisedQueueSize(monitoredItemCreateResult.revisedQueueSize);
if (debug >= 5) {
std::cout << "** Monitored item " << monitoredItemCreateRequest.itemToMonitor.nodeId
<< " succeeded with id " << monitoredItemCreateResult.monitoredItemId
<< " revised sampling interval " << monitoredItemCreateResult.revisedSamplingInterval
<< " revised queue size " << monitoredItemCreateResult.revisedQueueSize
<< std::endl;
else
std::cout << "** Monitored item " << monitoredItemCreateRequest.itemToMonitor.nodeId
<< " failed with error "
<< UA_StatusCode_name(monitoredItemCreateResult.statusCode)
<< std::endl;
}
} else {
std::cerr << "OPC UA record " << it->recConnector->getRecordName()
<< " monitored item " << monitoredItemCreateRequest.itemToMonitor.nodeId
<< " failed with error " << UA_StatusCode_name(monitoredItemCreateResult.statusCode)
<< std::endl;
}
i++;
}
Expand Down

0 comments on commit b63d50c

Please sign in to comment.