From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Stop infinite timeout DAQmx Read task

I'm continuously reading a finite amount of data with DAQmx Read (counter or voltage) in a while loop. Since the task is digitally triggered and I'm not sure when triggers will occur, the Read Timeout is set to infinite (-1). I would like to be able to stop the task using a button. I've tried using a second parallel loop checking the button state and calling Stop Task but that has not worked.
0 Kudos
Message 1 of 6
(4,188 Views)
You should be able to abort the read by calling DAQmx Control Task with the "abort" control code.

--Joe
0 Kudos
Message 2 of 6
(4,182 Views)
SteveP,

One method which you should be able to use to accomplish this is rather than calling read with an infinite timeout, is to poll the number of samples available using DAQmxGetReadAvailSampPerChan. If this number equals your finite acquisition size in samples per channel, then you know that your acquisition has completed and data is ready to be read. In a loop you can periodically check the number of samples available. Break out of this loop once all the samples you are expecting have arrived, or when you would like to abort. After this, call DAQmx Read if you haven't aborted. Since you will have ensured that all samples are available before you call read, you can specify a very small read timeout.

Hope this helps,
Dan
0 Kudos
Message 3 of 6
(4,181 Views)
Dan,

In Tradional NIDAQ, I'd been using AI Read with "number of scans to read" set to zero so it would return the "scan backlog". Nice to see a similar property exists in DAQmx. For me in DAQmx 7.4, the Read property is called Status > Total Samples per Channel Acquired (TotalSampPerChanAcquired). This works, but are you refering to something different or a method instead of a property ?

Steve
0 Kudos
Message 4 of 6
(4,171 Views)
Steve,

I am referring to the same property. The method I referenced is from our C API, and should return the same information as the property you are referring to in LabVIEW.

Sorry for the confusion,
Dan
0 Kudos
Message 5 of 6
(4,160 Views)
Just to clarify, there are two different properties being discussed here. The "available samples per channel" property is different than the "total samples per channel acquired" property. The "available samples per channel" property indicate how many samples per channel are available in the buffer. The "total samples per channel acquired" property indicates how many samples per channel have been acquired since the task started. For a finite acquisition with a single read, these properties will return the same value. However, in a continuous acquisition, the "available samples per channel" value will be decremented each time the DAQmx Read.vi is called by however many samples are read out of the buffer. The "total samples per channel acquired" property will continue to increase as the task acquires data, regardless of how much data is available in the buffer. With this explanation, the "available samples per channel" property is equivalent to the scan backlog in the Traditional DAQ driver. Both properties are available from a DAQmx Read property node under the Status menu. I hope this clears up any potential confusion.
0 Kudos
Message 6 of 6
(4,114 Views)