online analysis on background data, ni card analog input

2 次查看(过去 30 天)
Hi,
I am trying to get access to a global variable that is updated in the listener function of a ''DataAvialable'' event, relating to the startbackground for NI card analog input.
It seems that neigther a global variable nor the "UserData" of the daq session object are not updated before stoping the background recording. Is there any way around this to get online access to a variable that is updated in the listener function while the recording is still running?
Thanks,
Ehsan

回答(1 个)

Kenny Shu
Kenny Shu 2019-1-23
When the session's "UserData" variable is updated in the "DataAvailable" event callback, the result is immediately accessible from the workspace.
By setting up the listener as follows,
s1 = daq.createSession('ni');
s1.addAnalogOutputChannel('Dev1','ao1', 'Voltage');
s2 = daq.createSession('ni');
ch = s2.addAnalogInputChannel('Dev1','ai1', 'Voltage');
ch.TerminalConfig = 'SingleEnded';
s2.DurationInSeconds = 60;
lh = addlistener(s2, 'DataAvailable', @dataAvailableCallback);
s1.queueOutputData(linspace(0,10,30000)');
startBackground(s1)
startBackground(s2)
function dataAvailableCallback(src, event)
src.UserData = [src.UserData; event.Data];
end
you may access the live "UserData" while the acquisition continues in the background:
>> s2.UserData(end)
ans =
9.1314

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by