12-14-2012 12:49 PM
Hi,
I want to be able to read the most recent digital value from a CompactDAQ NI-9403 without waiting (timeout=0) for it. I have a task rate of 5 and if I call the DAQ read VI every 500ms I don't get any data. If I set the timeout to 0.3 it works; 0.2 doesn't work. I think I'm doing everything correctly but it seems I should have samples waiting for me and I don't. I'm using LabVIEW 2011 and DAQmx 9.3.5 and a simulated NI-9403. I have attached my VI and an image of it.
Is there some way of doing this so that I don't need to wait at all for the most recent value?
Thanks,
Albert
12-14-2012 01:18 PM
Hi Albert,
checking execution times with simulated hardware is kind of "tricky"...
I don't think you need to set buffer sizes and overwriting behaviour. You should simply set your sample rate (as you do now) and call your DAQmxRead with a timeout of 1/samplerate (minimum, add some milliseconds). Note: for requesting single samples this will only work for low sample rates...
12-14-2012 01:36 PM
When using continuous mode the Samples per Channel input of the DAQmx Timing VI sets the buffer size. I would just leave it unwired.
Though, the more I'm thinking about this, why use continuous sampling if you only care about the latest on-demand value? Set the sampling mode to finite with 1 sample. When you perform a read, you will get that data point.
12-14-2012 03:01 PM
> checking execution times with simulated hardware is kind of "tricky"...
I've found that simulated hardware is much faster than real hardware. Is this what you are saying or are you saying it is unreliable?
I want to minimize acquisition time. Waiting 1/samplerate is OK but I also want to understand what's happening. The help page for the DAQmx Read (VI) states:
timeout specifies the amount of time in seconds to wait for samples to become available. ... If you set timeout to 0, the VI tries once to read the requested samples and returns an error if it is unable to.
I take that to mean that if I set timeout to 0 then it will give me the number of samples I ask for if it has them. I asked for 1 sample and it should have 1 sample in the buffer by then. Am I not understanding the handling of timeout or is this a "tricky" behavior of simulated hardware? Maybe timeout only refers to reading an actual sample and not about what is in the buffer.
Thanks,
Albert
12-14-2012 03:25 PM
Hi Albert,
the timeout of DAQmxRead works like any other timeout for other LabVIEW functions: the function will wait for data as long as you specified the timeout!
When you set a sample rate of 5Hz and use a timeout of 0.5s for your DAQmxRead the function would wait upto 0.5s - but it will read a new value after 0.2s...
"I want to minimize acquisition time" means you should use higher sample rates...
12-14-2012 04:42 PM
Why would it have to wait at all if there are samples in the buffer and I want those most recent samples (continuous mode)?
Thanks,
Albert
12-15-2012 12:56 PM
Hi albert,
it will NOT wait if there are samples in the buffer (atleast equal or more than requested number of samples).
When there are no (or less then requested) samples in the buffer it will wait for your timeout value...
12-15-2012 02:02 PM
Then why do I need timeout to be nonzero (see my original post)? In my example, timeout is set to 0.3 but if it's zero I get no data and the error states that I have no samples.
Albert
12-17-2012 04:39 PM
I found the problem. It was because I should have set Offset to -1 not 0. I circled the correct value in red in my attachment to this reply. I also attached the working VI.
Albert