Data acquisition read "all" does not work properly
Show older comments
I use a National Instruments USB-6009 daq box for a long time now. For a new project I use Matlab R2025b instead of previous versions. In a loop I want to use the read function with the "all" option but no data is stored. If I interspere calls with a span of 1 everything works. Why? Here my code:
%% Prepare data acquisition
dq = daq('ni');
% Add a channel to the data acquisition object
Channel = addinput(dq, 'Dev1', 1:4, 'Voltage');
for i = 1 : 4
Channel(i).Range = [-10, 10];
Channel(i).TerminalConfig = 'SingleEnded';
end
dq.Rate = 250;
%% data acquisition loop
Results = zeros(5000, 5); Start = 0;
dq.flush;
start(dq, 'Duration', seconds(20));
while dq.Running
pause(0.2);
Span = dq.NumScansAvailable;
if Span == 0
Span = 1;
else
Span = "all";
end
[data, TimeStamps] = read(dq, Span, "OutputFormat", "Matrix");
% Store the acquired data in the Results array
if ~isempty(data)
Results(Start + 1 : Start + size(data, 1), :) = [TimeStamps, data];
Start = Start + size(data, 1);
end
end
% Stop the data acquisition
stop(dq);
Results = Results(1 : Start, :);
I have all updates installed for Matlab R2025b, the current version of the Data Acquisition Toolbox Support Package for National Instruments NI-DAQmx Devices and the appropriate NI-DAQmx driver. The code works but I do not understand why no data is retrieved with a permanent Span setting to "all".
Greetings Andreas
2 Comments
dpb
less than a minute ago
I presume you have verified that prior release still functions as before?
Is the problem that
Span = dq.NumScansAvailable;
is now never returning anything but "0" or that the "all" case never returns any data or does it also work if there is a single scan returned first? Does a single scan reset the NumScansAvailable value to zero?
Andreas Sprenger
about 2 hours ago
Accepted Answer
More Answers (0)
Categories
Find more on National Instruments Frame Grabbers 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!