Get recent scan data during continuous background sampling with DAQ
32 views (last 30 days)
Show older comments
Hello All,
I have posted on this previously, but still have not gotten any further. I am trying to do what should be simple. I am running continuous background sampling of a DAQ device using
start(d,'continuous)
and then go about some other commands. Periodically, say for instance every 0.5 [s], I want to check the most recent scans to see if a certain value has been reached. No matter how to try to do this, I cannot seem to make it work. Shouldn't it be simple to check the most recent scans while still doing the continuous background sampling using the "read" command?
In mock code, this is what I am trying to do
start(device)
...start a loop of some commands...
if ( 2 seconds since last scan check)
... store most recent scans and check value
end
read(device,'all')
stop(device)
It seems like it should be simple but I keep getting weird data when I try to do this. I do not understand if calling the read command reads data start from the last time "read" was called, or from the current scans, or what?
Thank you
0 Comments
Answers (1)
Suman
on 25 Sep 2024 at 6:57
Edited: Suman
on 25 Sep 2024 at 7:04
Hi Holden,
In the code snippet, I see that you are using "start(device)" function to start sampling. This will only acquire data for 1 sec as mentioned in the documentation. To do a continuous data acquisition, you need to use "start(device, 'continuous')". This will continue the background data acquisition unless stopped with the "stop" function.
Now, the "read(device)" function will return the single last unread data from the buffer and if you call the function again, it will give you the next unread data from the buffer. So yes, your assumption is correct that, "calling the read command reads data start from the last time "read" was called". Similarly, "read(device, numOfScan)" will return the last "numOfScan" number of unread data.
You can modify your code as follows:
function readAndCheck(device)
data = read(device);
%verify data as required
%stop(device) as required
end
start(device, 'continuous') // starts background acquisition
%create a timer here and and set the desired interval for reading the data
%and set the timer callback i.e., "timer.TimerFcn = @readAndCheck"
Please refer the documentation to learn how to use the timer object in matlab: https://in.mathworks.com/help/matlab/ref/timer.html
You can stop the data acquisition in the callback function once the required data is achieved.
Note that once the data acquisition has stopped, calling the "read" function will do a foreground acquisition to get the data.
I hope that helps!
0 Comments
See Also
Categories
Find more on Data Acquisition Toolbox Supported Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!