Nxlib function isn’t responding? 2

General Information

  • Product: C57-6-M
  • Serial Number: 244888
  • Ensenso SDK Version: 4.0.1502
  • Operating System: Windows 10 64bit
  • Data Attachments?
    • Profiler log

Problem / Question

Nxlib function isn’t responding?

In the environment associated with the question I previously consulted you about, a phenomenon occurred where the “retrieve” operation would not succeed.
Specifically, imaging proceeded without issues for the first 921 targets (which arrived at 8-second intervals), but the system reached a state where the result for the 922nd target was not returned by the camera.

I noticed the issue shortly after it occurred and captured a log, which I have attached here.

tmp_NxTreeEdit20260625(stop).enslog (6.8 MB)

settings.json (245 Bytes)

Could you please check the log to see if it contains any information that might help in investigating the cause?

Best regards,
K.N,

Hi,

the logs seems to be from an idle NxView instance, not from your program.

where the “retrieve” operation would not succeed.

What exactly do you mean by this? Your program created an NxLibCommand object for the Retrieve command and you are running execute() on it? Does it hang like the title of your questions seems to imply? Or does it result in an error? For the latter case, please check this guide on how to get information about errors from commands.

Hi,

First, thanks a lot for your quick response!

I apologize.
As you pointed out, I used the incorrect method to capture the log.
Instead of selecting NxTreeEdit, I launched TreeEdit from the bottom of NxView and captured the log that way.
I will refer to the information you provided and capture the log again the next time the issue occurs.

Best regards,
K.N,

HI,

Since it is difficult to reproduce this issue in the actual production environment,
we conducted an experiment involving the capture of a large number of images

(approximately 4,000 in total) using a local debugging environment (running in VS2015 debug mode).

Two issues occurred.
1.
The following exception occurred at a rate of approximately once per 900 captures .

(The same exception occurred at the same location 5 times .)

During the call to ‘execute(&result, _commandName, _wait);’ at line 3001 of of `nxLibFunctions.h`,
the `result` returned via `retrieve.execute();` was set to 17 (0x11), and an exception was raised within `checkReturnCode( )`.

	void execute(std::string const& _commandName, bool _wait = true) const
	{
		int result;
		execute(&result, _commandName, _wait);
		checkReturnCode(result);
	}

	void checkReturnCode(int returnCode) const
	{
		if (returnCode != NxLibOperationSucceeded) {
			throw NxLibException(slot().path, returnCode, token);
		}
	}


I have attached a screen capture taken at that time. transparent

tmp_NxTreeEdit20207053-RetrieveNonfinish.enslog (6.7 MB)

2.After approximately 4,500 captures, `Retrieve()` stopped returning a result.
In light of the previous failure to capture logs, I have attached the `enslog` obtained when the issue occurred. I have also attached a screen capture taken after forcing a break using the debug ger.

tmp_NxTreeEdit2020705-49-RetrieveNonfinish.enslog (19.9 MB)

Could you please let us know if you have any insights regarding this?
Thank you for your assist ance.

Best regards,
K.N,

Error 17 means that a command failed. The C API only returns this error code, but in this case the actual error message is written to the NxLib tree and you have to read it from there. See the guide I already linked above which explains this.

I don’t know what the error message was in your case, but for the Retrieve command it probably was a capture timeout, i.e. no image arrived on the computer in time. This can have different reasons. It is often caused by an unreliable network connection. Based on your other threads you are using hardware trigger, in that case it could also mean that no hardware trigger was received or it might have been at a time where the camera was not ready to handle it.

2.After approximately 4,500 captures, Retrieve() stopped returning a result.

Can you describe in more detail what happened? When the command is still processing the thread that started it should block in a call to nxLibWaitForType(). This is expected until the timeout passes. I cannot read all of your screenshot, but the stack trace of the active thread does not look like this, since it does not contain any of your code. It might be in another thread though.

What is the timeout you passed to the command? It should not take much longer than that, but when you specified a very long duration for the timeout it will wait for this time and can appear to hang while no image arrives. The error message of the other commands would be a hint to why that happens as described above.

Hi,

thank you for your reply.

An exception occurred at `retrieve.execute();` in the code shown below.

short DoCapture()
{
	NxLibCommand trigger(cmdTrigger);
	trigger.parameters()[itmSubset] = valAll;
	trigger.execute();

	NxLibCommand retrieve(cmdRetrieve);
	retrieve.parameters()[itmTimeout] = -1;
	retrieve.parameters()[itmCameras] = m_serial;	//Only 3D Camera
	retrieve.execute(static_cast<bool>(false));
	while (1) {
		std::this_thread::sleep_for(std::chrono::microseconds(10));
		if (retrieve.finished()) {
			retrieve.assertSuccessful();
			assert(retrieve.result()[m_serial][itmRetrieved].asBool());
			bool rc2 = retrieve.result()[m_serial][itmRetrieved].asBool();
			if (rc2) {
				break;
			}
		}
		if(Cancelbutton){
			retrieve.cancel();
			while (true) {
				if (retrieve.finished()) {
					return(1);
				}
			}
		}
	}
	retrieve.parameters()[itmTimeout] = 1000;
	retrieve.parameters()[itmCameras] = m_serial_C;
	retrieve.execute();	//<== An exception occurs in this function.
	return(0);
}

You listed some potential causes, but would modifying the relevant section as follows allow me to pinpoint the exact cause?

	retrieve.parameters()[itmTimeout] = 1000;
	retrieve.parameters()[itmCameras] = m_serial_C;
	try {
		retrieve.execute();	//<== An exception occurs in this function.
	} catch (NxLibException& e) {
		if (e.isCommandExecutionFailure()) {
			// The command above has failed to execute successfully. 
			//Print all information to identify what happened.
			std::string errorSymbol = e.getCommandErrorSymbol();
			std::string errorText = e.getCommandErrorText();
			std::string completeParametersAndResults = e.getToken()->item.asJson(true);
			std::cerr << "The execution of a command failed with error symbol \'" << errorSymbol << "\' " << std::endl;
			std::cerr << "and error text: " << errorText << std::endl;
			std::cerr << "The full command and all parameters in JSON format of the failed command were:" << std::endl
		          << completeParametersAndResults << std::endl;
		} else {
			std::cerr << "The NxLib API error " << e.getErrorCode() << " occurred when accessing the item at \'"
		          << e.getItemPath() << "\' with error text: " << e.getErrorText() << std::endl;
		}
	}
	return(0);

By the way, does this mean that the result of `retrieve.execute()` returning 17 (timeout) is something that does not normally occur?

2.I was continuously triggering the system and displaying the captured images and the capture count on the screen; however, I noticed that the captured images had stopped changing and the capture count had ceased incrementing. The attached image shows the screen state when I performed a forced break in VS2015 to identify the function where the process had stalled. The previously attached file is the “enslog” obtained after that forced break.
Given these circumstances, I was unable to determine the specific conditions that caused the error, which is why I collected the enslog.

Best regards,
K.N,

Yes, whenever you have an NxLibException use that pattern to extract the reason.

Well, it is an error during the command, which might or might not be normal during the operation. You have to check the error symbol and message to see what the error was and decide whether it is severe.

As for the hanging, I am still not sure whether the NxLib command actually does hang. Please check the error messages that you get for the other cases first.

Hi,

thank you for your reply.

I added `try-catch` code and conducted a reproduction test in the debug environment.
We were able to reproduce the exception that occurred approximately every 900 iterations and obtained the following information.

errorSymbol=“CaptureTimeout”
errorText = “Waiting for images timed out.”

The execution of a command failed with error symbol 'CaptureTimeout'
and error text: Waiting for images timed out.
The full command and all parameters in JSON format of the failed command were:
{
        "Command": null,
        "Parameters": null,
        "PersistentParameters": false,
        "Result": {
                "245218-Color": {
                        "Images": null,
                        "Retrieved": false
                },
                "ErrorSymbol": "CaptureTimeout",
                "ErrorText": "Waiting for images timed out.",
                "Execute": {
                        "Command": "Retrieve",
                        "Parameters": {
                                "Cameras": "245218-Color",
                                "OpenMP": {
                                        "Dynamic": 1
                                },
                                "Threads": 10,
                                "Timeout": 1000
                        }
                }
        },
        "Status": {
                "LatestMessage": null,
                "Messages": [
                ],
                "Progress": null,
                "Time": 1022.155699999999910688
        }
}

What should I do to resolve this issue?

Best regards,
K.N,

Hi

A CaptureTimeout can occur due to multiple reasons, from firewall to network issues. Have a look at the Network Performance guide and report back if the issue still happens.

Regards,
Miguel