Azzera filtri
Azzera filtri

online analysis on background data, ni card analog input

2 visualizzazioni (ultimi 30 giorni)
Ehsan
Ehsan il 14 Gen 2019
Modificato: Ehsan il 24 Gen 2019
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

Risposte (1)

Kenny Shu
Kenny Shu il 23 Gen 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 Commento
Ehsan
Ehsan il 23 Gen 2019
Modificato: Ehsan il 24 Gen 2019
this doesn't work in the continuous mode.
s2.IsContinunous = true;

Accedi per commentare.

Prodotti


Release

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by