From b63d50cfd281124023e7373e7ab1368f0835a2c4 Mon Sep 17 00:00:00 2001 From: Dirk Zimoch Date: Tue, 18 Jun 2024 15:20:30 +0200 Subject: [PATCH] unconditionally show error when monitor item fails --- devOpcuaSup/UaSdk/SubscriptionUaSdk.cpp | 19 ++++++++--------- .../open62541/SubscriptionOpen62541.cpp | 21 +++++++++---------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/devOpcuaSup/UaSdk/SubscriptionUaSdk.cpp b/devOpcuaSup/UaSdk/SubscriptionUaSdk.cpp index 339e9811..04bdb458 100644 --- a/devOpcuaSup/UaSdk/SubscriptionUaSdk.cpp +++ b/devOpcuaSup/UaSdk/SubscriptionUaSdk.cpp @@ -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()); } } } diff --git a/devOpcuaSup/open62541/SubscriptionOpen62541.cpp b/devOpcuaSup/open62541/SubscriptionOpen62541.cpp index 123ca78d..11648ac6 100644 --- a/devOpcuaSup/open62541/SubscriptionOpen62541.cpp +++ b/devOpcuaSup/open62541/SubscriptionOpen62541.cpp @@ -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(subContext)-> dataChange(monId, *static_cast(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++; }