From 0ca1c1f7dcb87e29ead1b45affa8f8d79ffc9b85 Mon Sep 17 00:00:00 2001 From: Moritz Walker Date: Wed, 12 Feb 2025 17:00:20 +0100 Subject: [PATCH] fix: disconnects while reading typedict --- Main.cpp | 15 ++++++++++++++- OpcUaClient/OpcUaInterface.hpp | 10 +++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Main.cpp b/Main.cpp index 0ea9aa95..a8a9cc40 100644 --- a/Main.cpp +++ b/Main.cpp @@ -33,6 +33,9 @@ #include #include #include +#include +#include + #include #include @@ -87,9 +90,19 @@ int main(int argc, char *argv[]) { LOG(INFO) << "Connection not established, exiting."; return -1; } + for (;;) { + try { + dashboardClient.ReadTypes(); + break; + } catch (Umati::Exceptions::ClientNotConnected e) { + LOG(INFO) << "Client disconnected while browsing types. Trying again."; + } catch (Umati::Exceptions::OpcUaNonGoodStatusCodeException e) { + LOG(INFO) << "Client no good while browsing types. Trying again."; + } + } - dashboardClient.ReadTypes(); dashboardClient.StartMachineObserver(); + while (running && !reset) { dashboardClient.Iterate(); } diff --git a/OpcUaClient/OpcUaInterface.hpp b/OpcUaClient/OpcUaInterface.hpp index 94f3f7ad..7cab870c 100644 --- a/OpcUaClient/OpcUaInterface.hpp +++ b/OpcUaClient/OpcUaInterface.hpp @@ -141,9 +141,13 @@ class OpcUaWrapper : public OpcUaInterface { request.nodesToReadSize = 1; UA_ReadResponse response = UA_Client_Service_read(client, request); - UA_String *ns = (UA_String *)response.results[0].value.data; - for (size_t i = 0; i < response.results[0].value.arrayLength; ++i) { - namespaceArray.push_back(std::string(ns[i].data, ns[i].data + ns[i].length)); + if (response.results != nullptr) { + UA_String *ns = (UA_String *)response.results[0].value.data; + for (size_t i = 0; i < response.results[0].value.arrayLength; ++i) { + namespaceArray.push_back(std::string(ns[i].data, ns[i].data + ns[i].length)); + } + } else { + LOG(INFO) << "Error updating namespace table."; } UA_ReadRequest_clear(&request); UA_ReadResponse_clear(&response);