Continuous Acquire, Store and Process data using DAQ Toolbox for NI-DAQ

5 ビュー (過去 30 日間)
Rajeev Yadav
Rajeev Yadav 2014 年 3 月 28 日
回答済み: Rajeev Yadav 2014 年 4 月 1 日
I made a very basic GUI that allows me to setup DAQ for acquisition. I use session based mode and run the AI process in background. When I invoke the listener to plot data, it always plots the data in a new figure instead of using the MAIN GUI figure axes handles.
However, when I run the gui in debugging mode, it always plots in the correct location.
Second, I want to analyze the signals while it is storing the file and plotting. Storing to file and plot the data works fine within the listerner callback function.
How do I get data in the main GUI and process it?
Any idea..
Here is my start AI code. Ignore handles as they are the items on the GUI.
s = daq.createSession ('ni');
if get(handles.cbChannel1, 'Value')
ch = s.addAnalogInputChannel(handles.BoardID, 0, 'Voltage');
ch.Coupling = 'DC';
ch.Name = 'Signal 1';
ch.Range = handles.VoltageRange;
end
if get(handles.cbChannel2, 'Value')
ch = s.addAnalogInputChannel(handles.BoardID, 1, 'Voltage');
ch.Coupling = 'DC';
ch.Name = 'Signal 2';
ch.Range = handles.VoltageRange;
end
if get(handles.cbChannel3, 'Value')
ch = s.addAnalogInputChannel(handles.BoardID, 2, 'Voltage');
ch.Coupling = 'DC';
ch.Name = 'SWEEP';
ch.Range = handles.VoltageRange;
end
if get(handles.cbChannel4, 'Value')
ch = s.addAnalogInputChannel(handles.BoardID, 3, 'Voltage');
ch.Coupling = 'DC';
ch.Name = 'FCHNG';
ch.Range = handles.VoltageRange;
end
s.Rate = handles.SampleRate;
s.NotifyWhenDataAvailableExceeds = str2double(get(handles.tNumSample, 'string'));
lh = s.addlistener('DataAvailable', @(src,event) plot(event.TimeStamps, event.Data));
s.IsContinuous = true;
s.startBackground();
  1 件のコメント
Walter Roberson
Walter Roberson 2014 年 3 月 28 日
Search for tag:always-parent and read my comments there

サインインしてコメントする。

採用された回答

Rajeev Yadav
Rajeev Yadav 2014 年 3 月 31 日
編集済み: Rajeev Yadav 2014 年 3 月 31 日
I tried your solution but I see an empty figure always being created on the function call. Here is how I inherited a fix to my problem.
set(gcf,'Visible','off') ; ax = handles.SpectrumPlot;
plot(ax, event.TimeStamps, event.Data);
ylim([handles.VoltageRange(1), handles.VoltageRange(2)]);
xlim([event.TimeStamps(1), event.TimeStamps(end)]);
ax points to the original figure handle.
However, I am unable to return data back to the main function via the listner function.
Any idea???
Thanks RY
  1 件のコメント
Walter Roberson
Walter Roberson 2014 年 3 月 31 日
Also if you defined the listener function as a subfunction of the main function then the subfunction could write to the variables in the main function.

サインインしてコメントする。

その他の回答 (1 件)

Rajeev Yadav
Rajeev Yadav 2014 年 4 月 1 日
I tried using the globals and handles. It didnt work. Seems like once you define a listner, it executes when the trigger is invoked but it doesn't update the GUIObject. Hence, it works like in parallel.

カテゴリ

Help Center および File ExchangeSimultaneous and Synchronized Operations についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by