function varargout = SERIAL_GUI(varargin)
% SERIAL_GUI M-menu_file for SERIAL_GUI.fig
% SERIAL_GUI, by itself, creates a new SERIAL_GUI or raises the existing
% singleton*.
%
% H = SERIAL_GUI returns the handle to a new SERIAL_GUI or the handle to
% the existing singleton*.
%
% SERIAL_GUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SERIAL_GUI.M with the given input arguments.
%
% SERIAL_GUI('Property','Value',...) creates a new SERIAL_GUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before SERIAL_GUI_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to SERIAL_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 SERIAL_GUI
% Last Modified by GUIDE v2.5 07-Oct-2009 17:48:43
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @SERIAL_GUI_OpeningFcn, ...
'gui_OutputFcn', @SERIAL_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 SERIAL_GUI is made visible.
function SERIAL_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 SERIAL_GUI (see VARARGIN)
% Choose default command line output for SERIAL_GUI
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes SERIAL_GUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = SERIAL_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 selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu 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 selection change in popupmenu2.
function popupmenu2_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns popupmenu2 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu2
% --- Executes during object creation, after setting all properties.
function popupmenu2_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu 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)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global serial1;%串口对象声明
global s_index;%串口下拉列表值
global s_baud;%波特率下拉列表值
name1 = get(handles.popupmenu1,'Value');%获得串口名称
switch name1
case 1
s_index = 'COM1';
case 2
s_index = 'COM2';
case 3
s_index = 'COM3';
case 4
s_index = 'COM4';
case 5
s_index = 'COM5';
case 6
s_index = 'COM6';
case 7
s_index = 'COM7';
case 8
s_index = 'COM8';
case 2
s_index = 'COM9';
end
name2 = get(handles.popupmenu2,'value');%获得波特率
switch name2
case 1
s_baud = 9600;
case 2
s_baud = 2400;
case 3
s_baud = 4800;
case 4
s_baud = 1200;
case 5
s_baud = 19200;
case 6
s_baud = 38400;
case 7
s_baud = 115200;
end
%建立串口对象
serial1 = serial(s_index,'baudrate',s_baud,'inputbuffersize',1024*8);
%设置超时时间,默认为60秒
switch get(handles.popupmenu5,'Value')
case 1
tout = 60;
case 2
tout = 10;
case 3
tout = 20;
case 4
tout = 30;
case 5
tout = 40;
case 6
tout = 50;
case 7
tout = 120;
end
serial1.Timeout = tout;
%打开串口
fopen(serial1);
%questdlg('串口已经打开,请在结束程序之前先关闭串口!','注意事项','好的','行','没问题');
%设定按钮的显示与隐藏属性
set(handles.pushbutton3,'visible','on');
set(handles.pushbutton2,'visible','off');
%串口打开以后才能启动采样
set(handles.pushbutton6,'visible','on');
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global serial1;
%关闭串口
fclose(serial1);
%删除串口对象
delete(serial1);
%清楚串口对象占用的内存
clear serial1;
%设定按钮的显示隐藏属性
set(handles.pushbutton3,'visible','off');
set(handles.pushbutton2,'visible','on');
%串口关闭以后不能启动采样
set(handles.pushbutton6,'visible','off');
% --- Executes on selection change in popupmenu3.
function popupmenu3_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns popupmenu3 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu3
% --- Executes during object creation, after setting all properties.
function popupmenu3_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu
MATLABserial-.rar_MATLAB 串口_matlab 串口 数据 采集_matlab 采集串口_matlab串口
版权申诉
187 浏览量
2022-07-14
01:26:28
上传
评论
收藏 5KB RAR 举报
小贝德罗
- 粉丝: 70
- 资源: 1万+
最新资源
- 基于opencv+yolov8实现目标追踪及驻留时长统计源码.zip
- 水稻病害基于Yolov8算法优化目标检测识别与AI辅助决策python源码+模型+使用说明.zip
- 海尔618算价表_七海5.20_16.00xlsx(1)(2).xlsx
- WebCrawler.scr
- 【计算机专业毕业设计】大学生就业信息管理系统设计源码.zip
- YOLO 数据集:8种路面缺陷病害检测【包含划分好的数据集、类别class文件、数据可视化脚本】
- JAVA实现Modbus RTU或Modbus TCPIP案例.zip
- 基于YOLOv8的FPS TPS AI自动锁定源码+使用步骤说明.zip
- JAVA实现Modbus RTU或Modbus TCPIP案例.zip
- 基于yolov8+streamlit的火灾检测部署源码+模型.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈