I want to do a VISA Read operation in such a way that if no data is available, the operation times out quickly. I tried setting the timeout to a short value (0 for immediate timeout, or 10 ms, etc.) and then calling viRead:
If viSetAttribute(handle, VI_ATTR_TMO_VALUE, VI_TMO_IMMEDIATE) = VI_SUCCESS Then
status = viGetAttribute(handle, VI_ATTR_TMO_VALUE, timeoutSet)
status = viRead(handle, buff, Len(buff), readCount)
or, the equivalent operations in LabView 2009.
I find that if I do this with a serial device, the time that viRead takes is very close to the timeout that I set (as it should be). However, if I do this with a USBTMC device (in this case, a TDS1012B oscilloscope), the timeout returned by viGetAttribute is always at least 50 ms (never 0=immediate), and viRead takes a minimum of 1.6 seconds to return if no data is present.
So, I'd like to know...
1. Is there a bug in the timeout code for USBTMC devices, or is the timeout set some other way?
2. Is there a VISA call that will tell me if data is available to be read (for GPIB and/or USBTMC devices), similar to the "Bytes at serial port" property for ASRL devices? Then I could avoid relying on the timeout.
3. Are there any VISA events that will tell me when data is available? Something analogous to the OnComm event of the Microsoft Comm control (for serial) or DataArrival event of the Microsoft Winsock control, or at least an event type for viEnableEvent() that would respond to incoming data.
This is using NI-VISA 5.0 on Windows XP.
I was wondering what happens if you set the timeout to something other than 0, like 20, for example. Does it still return 50?
In regards to your question earlier about being able to check if data is available, one thing you can try is the Service Request event (VI_EVENT_SERVICE_REQ). You can check out NI-VISA Help->User Reference->Message-Based Communication->Basic I/O Services->Status/Service Request Service document in the VISA Help for more information on using this event. There's also a CVI example that demonstrates using service requests called WaitSRQ_CVI.prj, which can be found in the example finder. I also just got my hands on a USBTMC device, so I am going to try to reproduce what you are seeing.
thanks for the suggestion. I tried waiting for events on the "Service Request" and "USB Interrupt" events - all other event types are unsupported - but they just time out. Doing some simple VISA Write and VISA Read calls don't seem to trigger these events. While the device does support the common 488.2 commands (*IDN, etc) I don't think it generates SRQ regularly.
I'm getting around it at the moment by writing my code to read from the instrument if and only if the previous command sent ends in a "?". It's an awkward way of doing it, but it kinda works for now.
That sounds like a reasonable workaround. At this point it seems like the issue may be with your specific USBTMC device. Have you tried any other devices?