online analysis on background data, ni card analog input

2 views (last 30 days)
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

Answers (1)

Kenny Shu
Kenny Shu on 23 Jan 2019
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
  1 Comment
Ehsan
Ehsan on 23 Jan 2019
Edited: Ehsan on 24 Jan 2019
this doesn't work in the continuous mode.
s2.IsContinunous = true;

Sign in to comment.

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!