Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Sampling using two systems: NI Data Acqusition combined with MexFunction Loop

1 visualización (últimos 30 días)
Eddy H
Eddy H el 22 de Abr. de 2016
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
Hi,
I am using matlab to sample data from a system connected through a NI card. The data is stored in a global variable called datastore. I am also sampling from a USB connected device using a mexfunction at a different sample rate using a loop - see code below.
Main code (abbreviated):
global datastore
datastore = [];
s = daq.createSession('ni');
s.DurationInSeconds = Trial_Time;
s.Rate = 1000;
ch_0 = addAnalogInputChannel(s,'Dev1','ai0','Voltage');
ch_1 = addAnalogInputChannel(s,'Dev1','ai3','Voltage');
lh = addlistener(s,'DataAvailable', @getData);
startBackground(s);
while toc <= Max_Time
if toc < i*(1/s_r)
else
timer(i, 1) = toc;
[Output1(i, 1)] = MyMexFunction;
i = i+1;
pause(0.01);
end
end
s.stop
delete(lh)
getData:
function getData(src,event)
global datastore
% hold on
datastore = [datastore event.Data'];
% plot(event.TimeStamps, event.Data)
end
I found that I have to include the pause(0.01) in the loop to allow the DAQ to populate the variable datastore, but this limits the rate I can sample the 2nd device at in the loop, and the pause function is somewhat unreliable over short time periods leading to missed samples.
Can anyone suggest an alternative to this set-up? I'm sure there must be a better way!
Also - What is the guidance on minimum pause time requires to collect samples - I can't find any documentation on this, and are there any alternative functions to pause that allow background data to be sampled?
Many thanks.

Respuestas (0)

La pregunta está cerrada.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by