Plotting data acquired through NI DAQ inside a GUI window

17 ビュー (過去 30 日間)
Artur Zych
Artur Zych 2019 年 9 月 27 日
編集済み: Artur Zych 2019 年 9 月 27 日
Hey everyone,
So I am trying to acquire data in a GUI by pressing a Start Button.
First, in the code below I created a DAQ session that is a handles, and it updates all the handles to include the DAQ session (by guidata function)
% --- Executes just before FlowLoopGUI is made visible.
function FlowLoopGUI_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to FlowLoopGUI (see VARARGIN)
% Choose default command line output for FlowLoopGUI
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% Start data aquisition for Temperature///////////////////////////////
s_temp=daq.createSession('ni');
addAnalogInputChannel(s_temp,'Dev2',0, 'Thermocouple');
s_temp.Rate = 6; %sampling rate
%sets TC type and units
tc = s_temp.Channels(1);
set(tc);
tc.ThermocoupleType = 'T';
tc.Units = 'Celsius';
%lh_temp = s_temp.addlistener('DataAvailable',@(src, event)logData(src, event, name));
%lh1_temp = s_temp.addlistener('DataAvailable', @(src,event) plot(event.TimeStamps, event.Data));
handles.s_temp = s_temp;
guidata(hObject, handles);
% UIWAIT makes FlowLoopGUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
Next, pressing the StartButton, I want to acquire data from the DAQ onto the GUI window. This is where I am having trouble...
The data isn't popping up on the window.
% --- Executes on button press in StartButton.
function StartButton_Callback(hObject, eventdata, handles)
% hObject handle to StartButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
FileName = get(handles.FileName,'String')
power = get(handles.HeatPower,'String')
TestNumber = get(handles.TestNumber,'String')
Date = get(handles.DateText,'String')
FileID = fopen(sprintf('%s.txt', FileName) , 'w');
fid = FileID;
set(handles.StartButton, 'UserData', fid);
fprintf(fid, ['Test Number: ', TestNumber '\n']);
fprintf(fid, ['Date: ', Date '\n']);
fprintf(fid, ['Wattage [W]: ' ,power '\n']);
%%%%/////THIS IS WHERE THE DAQ STARTS ACQUIRING DATA%%%%%%%%//////
handles.s_temp.IsContinuous = true;
lh_temp = addlistener(handles.s_temp,'DataAvailable',@(src, event)logData(src, event, name));
%lh_temp_temp = addlistener(handles.s_temp, 'DataAvailable',{@collectData,handles.axes1});
lh1_temp = addlistener(handles.s_temp,'DataAvailable', @(src,event) plotDataCont(event.TimeStamps, event.Data);
startBackground(handles.s_temp);
Here is the plotDataCont function
function plotDataCont(src,event)
hold on
axes(handles.axes1)
plot(event.TimeStamps, event.Data(:,1), 'r.');%...
% event.TimeStamps, event.Data(:,2), 'b.')
xlabel('time (sec)');
ylabel('Temperature (Celsius)');
legend( 'TC_1')
end
Thank you!

回答 (0 件)

カテゴリ

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