function varargout = gui(varargin) % GUI M-file for gui.fig % GUI, by itself, creates a new GUI or raises the existing % singleton*. % % H = GUI returns the handle to a new GUI or the handle to % the existing singleton*. % % GUI('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in GUI.M with the given input arguments. % % GUI('Property','Value',...) creates a new GUI or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before gui_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to gui_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help gui % Last Modified by GUIDE v2.5 02-Feb-2006 13:34:43 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @gui_OpeningFcn, ... 'gui_OutputFcn', @gui_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before gui is made visible. function gui_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 gui (see VARARGIN) % Choose default command line output for gui handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes gui wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = gui_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on button press in checkbox1. function checkbox1_Callback(hObject, eventdata, handles) % --- Executes on button press in checkbox2. function checkbox2_Callback(hObject, eventdata, handles) % --- Executes on button press in checkbox3. function checkbox3_Callback(hObject, eventdata, handles) % % --- Executes on button press in checkbox4. function checkbox4_Callback(hObject, eventdata, handles) % --- Executes on button press in checkbox5. function checkbox5_Callback(hObject, eventdata, handles) % --- Executes on button press in checkbox6. function checkbox6_Callback(hObject, eventdata, handles) % --- Executes on button press in checkbox7. function checkbox7_Callback(hObject, eventdata, handles) % --- Executes on button press in checkbox8. function checkbox8_Callback(hObject, eventdata, handles) %--- Executes on button press in checkbox9. function checkbox9_Callback(hObject, eventdata, handles) %--- Executes on button press in checkbox10. function checkbox10_Callback(hObject, eventdata, handles) % --- Executes on button press in checkbox11. %function checkbox11_Callback(hObject, eventdata, handles) % --- Executes on button press in checkbox12. %function checkbox12_Callback(hObject, eventdata, handles) function edit1_Callback(hObject, eventdata, handles) % --- Executes during object creation, after setting all properties. function edit1_CreateFcn(hObject, eventdata, handles) % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on button press in pushbutton1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function samplerate_Callback(hObject, eventdata, handles) % feedrate = str2double(get(hObject,'string')); % if isnan(feedrate) % errordlg('Give a numeric value','Bad Input','modal') % end % --- Executes during object creation, after setting all properties. function samplerate_CreateFcn(hObject, eventdata, handles) % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function time_Callback(hObject, eventdata, handles) % if isnan(time) % errordlg('Give a numeric value','Bad Input','modal') % end % --- Executes during object creation, after setting all properties. function time_CreateFcn(hObject, eventdata, handles) % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on button press in pushbutton2. function pushbutton2_Callback(hObject, eventdata, handles) fig = gcf; quit_reply = questdlg('Are you sure?'); if strcmp(quit_reply,'Yes') close(fig); end % --- Executes on button press in pushbutton3. function pushbutton3_Callback(hObject, eventdata, handles) % --- Executes on button press in pushbutton4. function pushbutton4_Callback(hObject, eventdata, handles) % chvalue(0)=get(handles.checkbox1,'Value'); chvalue(1)=get(handles.checkbox1,'Value'); chvalue(2)=get(handles.checkbox2,'Value'); chvalue(3)=get(handles.checkbox3,'Value'); chvalue(4)=get(handles.checkbox4,'Value'); chvalue(5)=get(handles.checkbox5,'Value'); chvalue(6)=get(handles.checkbox6,'Value'); chvalue(7)=get(handles.checkbox7,'Value'); chvalue(8)=get(handles.checkbox8,'Value'); chvalue(9)=get(handles.checkbox9,'Value'); chvalue(10)=get(handles.checkbox10,'Value'); % chvalue(11)=get(handles.checkbox11,'Value'); %chvalue(12)=get(handles.checkbox12,'Value'); % chvalue(7) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % This is for the inputs %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% k=1; for i=1:8 if chvalue(i)==1; v(k)=i-1; k=k+1; end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % This is for the outputs %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% k = 1;%r=[0 0]; outflag = 0; % flag to be set if there's an output requested for ii = 1:2 if chvalue(8+ii)==1 r(k)=ii-1; k=k+1; outflag = 1; end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Input parameters samplerate=str2double(get(handles.samplerate,'string')); sampletime=str2double(get(handles.time,'string')); samples=sampletime*samplerate; % if nochannels*samplerate>20000, % error('samplerate too high'); % end; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Output parameters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if outflag==1 % Execute only if an output is requested outsamp = str2double(get(handles.outsamplerate,'string')); outsamples = sampletime*outsamp; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%% end parameter definition %%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%% begin sampling using manual trigger %%%%%%%%%%%%%%%%%%% % Output stuff%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% AO = analogoutput('nidaq','Dev1'); mssg = 'addchannel(AO,r)'; eval(mssg); AO.SampleRate = outsamp; %AO.RepeatOutput = 4; AO.SamplesOutputFcnCount = outsamples; AO.SampleRate.ConstraintValue=[0 2.8e6]; AO.channel.OutputRange=[-10 10]; %AO.TriggerType='manual'; %ActualRate = get(AO,'SampleRate'); %freq = get(AO,'SamplesOutputFcnCount'); %set(AO,'SamplesOutputFcn',@daqdoc6_4disp) outfunc = signalfunc(sampletime,outsamples); putdata(AO,outfunc) end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %clear d t AI=analoginput('nidaq','Dev1'); mssg = 'addchannel(AI,v)'; eval(mssg); AI.SampleRate=samplerate; AI.SamplesPerTrigger=samples; AI.InputType='SingleEnded'; AI.TriggerType='manual'; AI.DriveAISenseToGround='Off'; AI.channel.InputRange=[-10 10]; AI.channel.SensorRange=[-10 10]; AI.channel.UnitsRange=[-10 10]; AI.SampleRate.ConstraintValue=[0 1.2e6]; % nochannels=2; %nochannels=length(v); % % if nochannels>1, % AI.Bufferingconfig=[round(samples/10*nochannels) 10]; % end; if outflag ==1 start(AI);start(AO); trigger(AI); [draw,t]=getdata(AI); stop(AI);stop(AO); delete(AI);delete(AO); else start(AI); trigger(AI); [draw,t]=getdata(AI); stop(AI); delete(AI); end axes(handles.axes1); plot(t,draw); aa=size(draw); zoom on; data(:,1)=t; data(:,2:aa(2)+1)=draw; save tempdata1.txt data -ASCII function pushbutton1_Callback(hObject, eventdata, handles) [filename,path]=uiputfile('*.txt','Save'); cd(path); % save(filename,'plot','tempdata1'); load tempdata1.txt; data = tempdata1; mssg = ['save ' filename ' data -ASCII']; eval(mssg); h=findobj('tag','fileName'); set(h,'string',filename); clear fileName %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % This function creates the OUTPUT signal % function outfunc = signalfunc(sampletime,outsamples) %data = ones(samples,1)*NaN; tt = linspace(0,sampletime,outsamples); fhz = 30; w = 2*pi*fhz; %w = 2*pi/1; %T = 1/fhz; outfunc = sin(w*tt)'; g = find(outfunc==max(abs(outfunc)),1); % find max value outfuncmax = outfunc(g); if outfunc(g)>=2 % Rescale to avoid V>2volts outfunc = outfunc/outfuncmax*1.98; end %data = data/data(g(1)) * 1.98; % signal to avoid high voltages %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%