From 5620c98eda6a968bfd2aaba4f504b8c8c80012d0 Mon Sep 17 00:00:00 2001 From: Thomas Stoddard Date: Wed, 13 May 2026 21:03:01 +0000 Subject: [PATCH] Examples: Add more error reporting --- examples/cpp/a2b/src/a2b.cpp | 3 +++ examples/cpp/analog_out/src/analog_out.cpp | 6 ++++++ examples/cpp/apperror/src/AppErrorExample.cpp | 7 +++++++ examples/cpp/coremini/src/coremini.cpp | 3 +++ examples/cpp/diskformat/src/DiskFormatExample.cpp | 4 +++- examples/cpp/flexray/src/FlexRayExample.cpp | 6 ++++++ examples/cpp/lin/src/LINExample.cpp | 7 +++++++ examples/cpp/livedata/src/LiveDataExample.cpp | 7 +++++++ examples/cpp/macsec/src/macsec.cpp | 6 ++++-- examples/cpp/mdio/src/MDIOExample.cpp | 7 +++++++ examples/cpp/mutex/src/MutexExample.cpp | 7 +++++++ examples/cpp/simple/src/SimpleExample.cpp | 7 +++++++ examples/cpp/spi/src/spi.cpp | 3 +++ examples/cpp/t1s/src/T1SSettingsExample.cpp | 6 ++++-- examples/cpp/t1s/src/T1SSymbolDecodingExample.cpp | 6 ++++-- examples/cpp/vsa/src/VSAExample.cpp | 4 +++- 16 files changed, 81 insertions(+), 8 deletions(-) diff --git a/examples/cpp/a2b/src/a2b.cpp b/examples/cpp/a2b/src/a2b.cpp index b9edfbb8..9da9d1d8 100644 --- a/examples/cpp/a2b/src/a2b.cpp +++ b/examples/cpp/a2b/src/a2b.cpp @@ -406,6 +406,9 @@ int main(int argc, char** argv) { if(it == devices.end()) { std::cerr << "Could not find RAD-A2B." << std::endl; + auto lastError = icsneo::GetLastError(); + if(lastError.getType() != icsneo::APIEvent::Type::NoErrorFound) + std::cerr << lastError << std::endl; return EXIT_FAILURE; } diff --git a/examples/cpp/analog_out/src/analog_out.cpp b/examples/cpp/analog_out/src/analog_out.cpp index 35bcd9c5..7e9ca19f 100644 --- a/examples/cpp/analog_out/src/analog_out.cpp +++ b/examples/cpp/analog_out/src/analog_out.cpp @@ -92,6 +92,9 @@ int main(int argc, const char** argv) { if(!device) { std::cerr << "Device with serial " << serial << " not found" << std::endl; + auto lastError = icsneo::GetLastError(); + if(lastError.getType() != icsneo::APIEvent::Type::NoErrorFound) + std::cerr << lastError << std::endl; return -1; } } else { @@ -99,6 +102,9 @@ int main(int argc, const char** argv) { auto devices = icsneo::FindAllDevices(); if(devices.empty()) { std::cerr << "No devices found" << std::endl; + auto lastError = icsneo::GetLastError(); + if(lastError.getType() != icsneo::APIEvent::Type::NoErrorFound) + std::cerr << lastError << std::endl; return -1; } device = devices[0]; diff --git a/examples/cpp/apperror/src/AppErrorExample.cpp b/examples/cpp/apperror/src/AppErrorExample.cpp index 1e690584..0adcb545 100644 --- a/examples/cpp/apperror/src/AppErrorExample.cpp +++ b/examples/cpp/apperror/src/AppErrorExample.cpp @@ -17,6 +17,13 @@ int main() { auto devices = icsneo::FindAllDevices(); std::cout << "OK, " << devices.size() << " device" << (devices.size() == 1 ? "" : "s") << " found" << std::endl; + if(devices.empty()) { + auto lastError = icsneo::GetLastError(); + if(lastError.getType() != icsneo::APIEvent::Type::NoErrorFound) + std::cout << lastError << std::endl; + return 0; + } + // List off the devices for(auto& device : devices) std::cout << '\t' << device->describe() << " @ Handle " << device->getNeoDevice().handle << std::endl; diff --git a/examples/cpp/coremini/src/coremini.cpp b/examples/cpp/coremini/src/coremini.cpp index 53f3fc49..ad8f55d8 100644 --- a/examples/cpp/coremini/src/coremini.cpp +++ b/examples/cpp/coremini/src/coremini.cpp @@ -33,6 +33,9 @@ int main(int argc, char** argv) { if(it == devices.end()) { std::cout << "Failed to find device." << std::endl; + auto lastError = icsneo::GetLastError(); + if(lastError.getType() != icsneo::APIEvent::Type::NoErrorFound) + std::cout << lastError << std::endl; return EXIT_FAILURE; } diff --git a/examples/cpp/diskformat/src/DiskFormatExample.cpp b/examples/cpp/diskformat/src/DiskFormatExample.cpp index ec9825f2..a5ffd55f 100644 --- a/examples/cpp/diskformat/src/DiskFormatExample.cpp +++ b/examples/cpp/diskformat/src/DiskFormatExample.cpp @@ -12,7 +12,9 @@ int main() { std::cout << "OK, " << devices.size() << " device" << (devices.size() == 1 ? "" : "s") << " found" << std::endl; if(devices.empty()) { - std::cout << "error: no devices found" << std::endl; + auto lastError = icsneo::GetLastError(); + if(lastError.getType() != icsneo::APIEvent::Type::NoErrorFound) + std::cout << lastError << std::endl; return -1; } diff --git a/examples/cpp/flexray/src/FlexRayExample.cpp b/examples/cpp/flexray/src/FlexRayExample.cpp index 6a2c8a83..98962c56 100644 --- a/examples/cpp/flexray/src/FlexRayExample.cpp +++ b/examples/cpp/flexray/src/FlexRayExample.cpp @@ -138,6 +138,12 @@ std::vector> makeDummyFlexRayMessages(si int main() { auto devices = icsneo::FindAllDevices(); + if(devices.empty()) { + auto lastError = icsneo::GetLastError(); + if(lastError.getType() != icsneo::APIEvent::Type::NoErrorFound) + std::cerr << lastError << std::endl; + return -1; + } std::shared_ptr flexrayDevice = nullptr; for (auto&& device : devices) { if (device->getExtension("FlexRay")) { diff --git a/examples/cpp/lin/src/LINExample.cpp b/examples/cpp/lin/src/LINExample.cpp index ce074b47..6901aa7b 100644 --- a/examples/cpp/lin/src/LINExample.cpp +++ b/examples/cpp/lin/src/LINExample.cpp @@ -15,6 +15,13 @@ int main() { // You now hold the shared_ptrs for these devices, you are considered to "own" these devices from a memory perspective std::cout << "OK, " << devices.size() << " device" << (devices.size() == 1 ? "" : "s") << " found" << std::endl; + if(devices.empty()) { + auto lastError = icsneo::GetLastError(); + if(lastError.getType() != icsneo::APIEvent::Type::NoErrorFound) + std::cout << lastError << std::endl; + return 0; + } + // List off the devices for(auto& device : devices) std::cout << '\t' << device->describe() << " @ Handle " << device->getNeoDevice().handle << std::endl; diff --git a/examples/cpp/livedata/src/LiveDataExample.cpp b/examples/cpp/livedata/src/LiveDataExample.cpp index 7b6ee329..83b3ffb0 100644 --- a/examples/cpp/livedata/src/LiveDataExample.cpp +++ b/examples/cpp/livedata/src/LiveDataExample.cpp @@ -14,6 +14,13 @@ int main() { auto devices = icsneo::FindAllDevices(); // This is type std::vector> std::cout << "OK, " << devices.size() << " device" << (devices.size() == 1 ? "" : "s") << " found" << std::endl; + if(devices.empty()) { + auto lastError = icsneo::GetLastError(); + if(lastError.getType() != icsneo::APIEvent::Type::NoErrorFound) + std::cout << lastError << std::endl; + return 0; + } + // List off the devices for(auto& device : devices) std::cout << '\t' << device->describe() << " @ Handle " << device->getNeoDevice().handle << std::endl; diff --git a/examples/cpp/macsec/src/macsec.cpp b/examples/cpp/macsec/src/macsec.cpp index 0e930233..e30ef7d0 100644 --- a/examples/cpp/macsec/src/macsec.cpp +++ b/examples/cpp/macsec/src/macsec.cpp @@ -9,8 +9,10 @@ int main(int, char**) { auto devices = icsneo::FindAllDevices(); - if(devices.size() == 0) { - std::cout << "No device found" << std::endl; + if(devices.empty()) { + auto lastError = icsneo::GetLastError(); + if(lastError.getType() != icsneo::APIEvent::Type::NoErrorFound) + std::cout << lastError << std::endl; return -1; } diff --git a/examples/cpp/mdio/src/MDIOExample.cpp b/examples/cpp/mdio/src/MDIOExample.cpp index 68cd31f4..68fef81a 100644 --- a/examples/cpp/mdio/src/MDIOExample.cpp +++ b/examples/cpp/mdio/src/MDIOExample.cpp @@ -48,6 +48,13 @@ int main() // You now hold the shared_ptrs for these devices, you are considered to "own" these devices from a memory perspective std::cout << "OK, " << devices.size() << " device" << (devices.size() == 1 ? "" : "s") << " found" << std::endl; + if(devices.empty()) { + auto lastError = icsneo::GetLastError(); + if(lastError.getType() != icsneo::APIEvent::Type::NoErrorFound) + std::cout << lastError << std::endl; + return 0; + } + // List off the devices for (auto &device : devices) std::cout << '\t' << device->describe() << " @ Handle " << device->getNeoDevice().handle << std::endl; diff --git a/examples/cpp/mutex/src/MutexExample.cpp b/examples/cpp/mutex/src/MutexExample.cpp index 30b2c720..059730da 100644 --- a/examples/cpp/mutex/src/MutexExample.cpp +++ b/examples/cpp/mutex/src/MutexExample.cpp @@ -76,6 +76,13 @@ int main() { // You now hold the shared_ptrs for these devices, you are considered to "own" these devices from a memory perspective std::cout << "OK, " << devices.size() << " device" << (devices.size() == 1 ? "" : "s") << " found" << std::endl; + if(devices.empty()) { + auto lastError = icsneo::GetLastError(); + if(lastError.getType() != icsneo::APIEvent::Type::NoErrorFound) + std::cout << lastError << std::endl; + return 0; + } + // List off the devices for(auto& device : devices) std::cout << '\t' << device->describe() << " @ Handle " << device->getNeoDevice().handle << std::endl; diff --git a/examples/cpp/simple/src/SimpleExample.cpp b/examples/cpp/simple/src/SimpleExample.cpp index 006be613..140200f9 100644 --- a/examples/cpp/simple/src/SimpleExample.cpp +++ b/examples/cpp/simple/src/SimpleExample.cpp @@ -22,6 +22,13 @@ int main() { // You now hold the shared_ptrs for these devices, you are considered to "own" these devices from a memory perspective std::cout << "OK, " << devices.size() << " device" << (devices.size() == 1 ? "" : "s") << " found" << std::endl; + if(devices.empty()) { + auto lastError = icsneo::GetLastError(); + if(lastError.getType() != icsneo::APIEvent::Type::NoErrorFound) + std::cout << lastError << std::endl; + return 0; + } + // List off the devices for(auto& device : devices) std::cout << '\t' << device->describe() << " @ Handle " << device->getNeoDevice().handle << std::endl; diff --git a/examples/cpp/spi/src/spi.cpp b/examples/cpp/spi/src/spi.cpp index 3cdf16bd..e48afd9e 100644 --- a/examples/cpp/spi/src/spi.cpp +++ b/examples/cpp/spi/src/spi.cpp @@ -86,6 +86,9 @@ int main(int argc, const char** argv) { } if(!device) { std::cerr << "Failed to find device" << std::endl; + auto lastError = icsneo::GetLastError(); + if(lastError.getType() != icsneo::APIEvent::Type::NoErrorFound) + std::cerr << lastError << std::endl; std::cerr << usage; return -1; } diff --git a/examples/cpp/t1s/src/T1SSettingsExample.cpp b/examples/cpp/t1s/src/T1SSettingsExample.cpp index 805f9382..3ded0502 100644 --- a/examples/cpp/t1s/src/T1SSettingsExample.cpp +++ b/examples/cpp/t1s/src/T1SSettingsExample.cpp @@ -216,8 +216,10 @@ int main() { auto devices = icsneo::FindAllDevices(); std::cout << "OK, " << devices.size() << " device" << (devices.size() == 1 ? "" : "s") << " found" << std::endl; - if (devices.empty()) { - std::cout << "No devices found!" << std::endl; + if(devices.empty()) { + auto lastError = icsneo::GetLastError(); + if(lastError.getType() != icsneo::APIEvent::Type::NoErrorFound) + std::cout << lastError << std::endl; return 1; } diff --git a/examples/cpp/t1s/src/T1SSymbolDecodingExample.cpp b/examples/cpp/t1s/src/T1SSymbolDecodingExample.cpp index 4269e8bd..52605567 100644 --- a/examples/cpp/t1s/src/T1SSymbolDecodingExample.cpp +++ b/examples/cpp/t1s/src/T1SSymbolDecodingExample.cpp @@ -260,8 +260,10 @@ int main() { auto devices = icsneo::FindAllDevices(); std::cout << "OK, " << devices.size() << " device" << (devices.size() == 1 ? "" : "s") << " found" << std::endl; - if (devices.empty()) { - std::cerr << "No devices found!" << std::endl; + if(devices.empty()) { + auto lastError = icsneo::GetLastError(); + if(lastError.getType() != icsneo::APIEvent::Type::NoErrorFound) + std::cerr << lastError << std::endl; return 1; } diff --git a/examples/cpp/vsa/src/VSAExample.cpp b/examples/cpp/vsa/src/VSAExample.cpp index 40b2c787..ae456d39 100644 --- a/examples/cpp/vsa/src/VSAExample.cpp +++ b/examples/cpp/vsa/src/VSAExample.cpp @@ -106,7 +106,9 @@ int main(int argc, char* argv[]) { auto devices = icsneo::FindAllDevices(); if(devices.empty()) { - std::cout << "error: no devices found" << std::endl; + auto lastError = icsneo::GetLastError(); + if(lastError.getType() != icsneo::APIEvent::Type::NoErrorFound) + std::cout << lastError << std::endl; return -1; }