LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx, Continuously Sampled, Digital, Most Recent Value

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

Download All
0 Kudos
Message 1 of 9
(3,762 Views)

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...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 9
(3,756 Views)

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.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 9
(3,754 Views)

> 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

0 Kudos
Message 4 of 9
(3,748 Views)

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...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 9
(3,746 Views)

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

0 Kudos
Message 6 of 9
(3,740 Views)

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...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 9
(3,729 Views)

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

0 Kudos
Message 8 of 9
(3,720 Views)

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

Download All
0 Kudos
Message 9 of 9
(3,686 Views)