大家好,我是一个matlab初学者,最近在做一个matlab读串口数据GUI的显示界面,控件的Callback函数老是添加不上去,四处询问老师,却让我放弃用matlab去做界面,很是失落,打击了一个作为matlab爱好者的信心,因此求教各位朋友,代码的框架和说明都在程序注释里,希望有人给看看,帮助一下我
function varargout = v4(varargin)
%V4 M-file for v4.fig
% V4, by itself, creates a new V4 or raises the existing
% singleton*.
%
% H = V4 returns the handle to a new V4 or the handle to
% the existing singleton*.
%
% V4('Property','Value',...) creates a new V4 using the
% given property value pairs. Unrecognized properties are passed via
% varargin to v4_OpeningFcn. This calling syntax produces a
% warning when there is an existing singleton*.
%
% V4('CALLBACK') and V4('CALLBACK',hObject,...) call the
% local function named CALLBACK in V4.M with the given input
% arguments.
%
% *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 v4
% Last Modified by GUIDE v2.5 20-Sep-2011 20:24:30
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @v4_OpeningFcn, ...
'gui_OutputFcn', @v4_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 v4 is made visible.
function v4_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 unrecognized PropertyName/PropertyValue pairs from the
% command line (see VARARGIN)
% Choose default command line output for v4
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes v4 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = v4_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;
%-------------------------------------------回调函数部分----------------------------------------%
function pushbutton1_openSerial_Callback(hObject, eventdata, handles)%串口设置及连接
%=======================串口初始化==================================================%
global ComQuerySize;
ComQuerySize = 500;%接收到的数据量
s=serial('COM2','DataBit',8,'StopBit',1);%设置帧格式
s.Baudrate =4800;%设置波特率
s.InputBufferSize = 512 ; %接收缓存区大小
% s.OutputBufferSize = 5000; %发送缓存区大小
s.Timeout = 30 ;
s.ReadAsyncMode = 'continuous';%设置读数方式
s.BytesAvailableFcnMode = 'byte';
s.BytesAvailableFcnCount = ComQuerySize;
% s.BytesAvailableFcn = @pushbutton1_open_Callback;%接收数据后的触发函数
%函数名为open_callback
s.Terminator = 'CR';
fopen(s);
A=fread(s,196);
%====================串口初始化结束==================================================%%
function popupmenu1_Select_Callback(hObject, eventdata, handles)%房间选择选项(2个选项)
%--------------------------------------------------------------------------
% 使用textwrap()函数可以在静态文本框中多行显示具体显示7*7的矩阵 %
% 说明:显示的数据如果大于40字符显示为红色,小于0字符显示为蓝色 %
%--------------------------------------------------------------------------
function pushbutton2_Display1_Callback(hObject, eventdata, handles)%显示第一层
function pushbutton3_Display2_Callback(hObject, eventdata, handles)%显示第二层
function pushbutton4_Display3_Callback(hObject, eventdata, handles)%显示第三层
function pushbutton5_Display4_Callback(hObject, eventdata, handles)%显示第四层
function popupmenu2_Plotfig_Callback(hObject, eventdata, handles)% imagsc;surf;mesh;
function pushbutton6_Savedata_Callback(hObject, eventdata, handles)%保存本页数据及生成图片
function pushbutton10_Close_Callback(hObject, eventdata, handles)%关闭串口并清除缓存数据
global s;
fclose(s);
delete(s);
clear s ;
%%%%%%%%%%%END%%%%%%%%%%%%%%END%%%%%%%%%%%%%END%%%%%%%%%%%%%%END%%%%%%%%%%%%END%%%%%%%%
[本帖最后由 matl787 于 2011-9-20 21:45 编辑]
2011-9-20 21:45 上传
点击文件名下载附件
3.53 KB, 下载次数: 25875
2011-9-20 21:45 上传
点击文件名下载附件
3.53 KB, 下载次数: 31996
这个是GUI界面