08-18-2012 07:40 PM
I have a problem with NI-VISA (5.1.2 Win7) over GPIB when performing an asynchronous read after a previous read has timed out. I am getting the status VI_ERROR_IN_PROGRESS from viReadAsync() once a timeout has been triggered and I cannot find out what needs to be done to clear the error condition to recover from the timeout.
The following code snippet has been stripped of error handling to simplify things. I am testing this with an HP3478A which responds to reads with the current measurement value without need for a query command like modern instruments.
// read async #1 with 1000ms timeout. This succeeds
viReadAsync(vi, (ViBuf)buf, sizeof(buf), &job_id);
rc1 = viWaitOnEvent(vi, VI_EVENT_IO_COMPLETION, 1000, &event_type, &context);
viClose(context);
// read async #2 with 1 ms timeout. This fails with a timeout as expected
viReadAsync(vi, (ViBuf)buf, sizeof(buf), &job_id);
rc2 = viWaitOnEvent(vi, VI_EVENT_IO_COMPLETION, 1, &event_type, &context);
viClose(context);
// read async #3. This fails with VI_ERROR_IN_PROGRESS for some reason
rc3 = viReadAsync(vi, (ViBuf)buf, sizeof(buf), &job_id);
// can't recover from this point on...
rc1 is VI_SUCCESS which validates the setup code I've left out
rc2 is VI_ERROR_TMO which we expect since 1ms is too short for the DMM I have connected
rc3 is VI_ERROR_IN_PROGRESS.
The documentation says almost nothing about VI_ERROR_IN_PROGRESS. Can anyone provide a clue on how to properly recover from VI_ERROR_TMO which seems to be causing it to happen? I've tried calling functions like viDiscardEvents() and viFlush() but they have no effect.
Thanks
08-21-2012 10:44 PM
Did you try viTerminate() and/or viClear() ?