Matlab GUI interface for acquiring data from NIDAQ

Hello Everybody! I'm writing a code for a GUI interface that plots and saves data from a National instruments DAQ linked to a Kistler Balance Board. I'm using the global variables for passing the data from the function fun_ext_plot_axes_KiStLeR to the GUI. I know that the global variables are not the best choice for a GUI, but I tried also with setappdata and getappdata without any good results. Below I reported the code of the button that starts the communication with the DAQ and the external function fun_ext_plot_axes_KiStLer, that plots the data from the DAQ. My functions plot the data, but they return the global variables data and time empty, so I cant'save them. Anyone of you know why or can give me any suggestion? Thanks in advance for the kind attention.
function START_Callback(hObject, eventdata, handles)
%data is a matrix that contains the data from the balance board, time is the
%array containing the TimeStemps, while plot_handles is the handler of the
%axes
global data time plot_handles
if strcmp(get(hObject,'String'),'START')
set(hObject,'String','STOP')
plot_handles=handles.plot_axes;
%create a daq session
handles.s=daq.createSession('ni');
s=handles.s;
s.Rate=1024;
% the data streaming is continuous
s.IsContinuous=true;
%add the analog channel
Fy14=addAnalogInputChannel(s,'Dev1',0,'Voltage');
Fx34=addAnalogInputChannel(s,'Dev1',1,'Voltage');
Fx12=addAnalogInputChannel(s,'Dev1',2,'Voltage');
Fz3=addAnalogInputChannel(s,'Dev1',3,'Voltage');
Fz2=addAnalogInputChannel(s,'Dev1',4,'Voltage');
Fz1=addAnalogInputChannel(s,'Dev1',5,'Voltage');
Fy23=addAnalogInputChannel(s,'Dev1',6,'Voltage');
Fz4=addAnalogInputChannel(s,'Dev1',7,'Voltage');
%create event listener
handles.lh = addlistener(s,'DataAvailable', @fun_ext_plot_axes_KiStLeR);
s.startBackground();
% handles.time and handles. data are empty!
handles.time=time;
handles.data=data;
guidata(hObject,handles);
elseif strcmp(get(hObject,'String'),'STOP')
set(hObject,'String','OK')
s=handles.s;
s.stop();
guidata(hObject,handles);
delete(handles.lh);
delete(s);
oper_reset_button(0);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function fun_ext_plot_axes_KiStLeR(src,event)
%data is a matrix that contain the data from the balance board, time is the
%array contained the TimeStemps, while plot_handles is the handler of the
%axes
global time data plot_handles
%I create persistent variable, so I don't loose data at any loop.
persistent tempData tempTime tempFx tempFy tempFz
if(isempty(tempData))
tempData = [];
end
if(isempty(tempTime))
tempTime = [];
end
tempTime=[tempTime;event.TimeStamps];
tempData=[tempData;event.Data];
fy14=tempData(:,1);
fx34=tempData(:,2);
fx12=tempData(:,3);
fz3=tempData(:,4);
fz2=tempData(:,5);
fz1=tempData(:,6);
fy23=tempData(:,7);
fz4=tempData(:,8);
tempFx=fx12+fx34;
tempFy=fy14+fy23;
tempFz=fz1+fz2+fz3+fz4;
time=tempTime;
data=tempData;
Fx=tempFx;
Fy=tempFy;
Fz=tempFz;
plot(plot_handles,tempTime,Fz,'k')

1 commentaire

hello Anna, I'm new in matlab and i have to creat a GUI for Kristler force plate. i'm having the same problem thatn you posted in mathworks. could you please tell me how did you fixed thank you so much

Connectez-vous pour commenter.

Réponses (0)

Question posée :

le 20 Oct 2015

Commenté :

le 27 Fév 2018

Community Treasure Hunt

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

Start Hunting!

Translated by