필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

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

조회 수: 1 (최근 30일)
Eddy H
Eddy H 2016년 4월 22일
마감: MATLAB Answer Bot 2021년 8월 20일
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.

답변 (0개)

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by