Nxlib function isn't responding?

Is there a way to keep the while loop as is and collect logs that will help identify the cause?

To get complete logs it would be better to limit the frequency of the polling. Also to save some CPU time.

Currently, the Retrieve command has a timeout value of -1. What is the difference between this and specifying 0?

I would prefer the variant with timeout 0, since it simplifies canceling. You can simply exit the function without any further cleanup. But timeout -1 and canceling the command as in your snippet is also possible. You just have to be more careful about the error handling and cleanup.

if (retrieve.finished()) {
    bool rc2 = retrieve.result()[m_serial][itmRetrieved].asBool();
    if (rc2) {
        break;
    }
}

This does not check the command result. When the command exits with an error, it will be finished, but Retrieved is false, so you end up in an infinite loop.

A better variant would be something like this:

if (retrieve.finished()) {
    // Throws an exception when the command failed.
    retrieve.assertSuccessful();

    // You can check the Retrieved flag here, but it is redundant. When you get
    // here and the command exited successfully, an image should have been
    // retrieved since the command was executed for a single camera.
    assert(retrieve.result()[m_serial][itmRetrieved].asBool());

    break;
}
1 Like