Skip to content

Commit

Permalink
fix: disconnects while reading typedict
Browse files Browse the repository at this point in the history
  • Loading branch information
wlkrm committed Feb 12, 2025
1 parent b09ea53 commit 0ca1c1f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
15 changes: 14 additions & 1 deletion Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
#include <ConfigureLogger.hpp>
#include <ConfigurationJsonFile.hpp>
#include <Exceptions/ConfigurationException.hpp>
#include <Exceptions/OpcUaNonGoodStatusCodeException.hpp>
#include <Exceptions/ClientNotConnected.hpp>

#include <chrono>
#include <iomanip>

Expand Down Expand Up @@ -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();
}
Expand Down
10 changes: 7 additions & 3 deletions OpcUaClient/OpcUaInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0ca1c1f

Please sign in to comment.