function varargout = SerialGUI2(varargin)
% SERIALGUI2 MATLAB code for SerialGUI2.fig
% SERIALGUI2, by itself, creates a new SERIALGUI2 or raises the existing
% singleton*.
%
% H = SERIALGUI2 returns the handle to a new SERIALGUI2 or the handle to
% the existing singleton*.
%
% SERIALGUI2('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SERIALGUI2.M with the given input arguments.
%
% SERIALGUI2('Property','Value',...) creates a new SERIALGUI2 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before SerialGUI2_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to SerialGUI2_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 SerialGUI2
% Last Modified by GUIDE v2.5 24-Dec-2020 19:34:29
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @SerialGUI2_OpeningFcn, ...
'gui_OutputFcn', @SerialGUI2_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 SerialGUI2 is made visible.
function SerialGUI2_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 SerialGUI2 (see VARARGIN)
% Choose default command line output for SerialGUI2
handles.output = hObject;
% handles structure with handles and user data (see GUIDATA)
global port
global baud
global datbit
global stobit
global parit
scoms = instrfind; %读取所有存在的端口
if ~isempty(scoms)
stopasync(scoms);
fclose(scoms);
delete(scoms); %停止并且删除串口对象
end
fsom = instrhwinfo('serial');
port = cell2mat(fsom.SerialPorts);
baud = 115200;
datbit = 8;
stobit = 1;
parit = 'None';
set(handles.serialcom,'String',port);
set(handles.Baud,'Value',5);
set(handles.databit,'Value',4);
set(handles.stopbit,'Value',1);
set(handles.parity,'Value',1);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes SerialGUI2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = SerialGUI2_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 Baud.
function Baud_Callback(hObject, eventdata, handles)
% hObject handle to Baud (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global baud
val = get(handles.Baud,'Value');
switch val
case 1
baud = 4800;
case 2
baud = 9600;
case 3
baud = 14400;
case 4
baud = 19200;
case 5
baud = 115200;
end
% Hints: contents = cellstr(get(hObject,'String')) returns Baud contents as cell array
% contents{get(hObject,'Value')} returns selected item from Baud
% --- Executes during object creation, after setting all properties.
function Baud_CreateFcn(hObject, eventdata, handles)
% hObject handle to Baud (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 databit.
function databit_Callback(hObject, eventdata, handles)
% hObject handle to databit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global datbit
val = get(handles.databit,'Value');
switch val
case 1
datbit = 5;
case 2
datbit = 6;
case 3
datbit = 7;
case 4
datbit = 8;
end
% Hints: contents = cellstr(get(hObject,'String')) returns databit contents as cell array
% contents{get(hObject,'Value')} returns selected item from databit
% --- Executes during object creation, after setting all properties.
function databit_CreateFcn(hObject, eventdata, handles)
% hObject handle to databit (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 stopbit.
function stopbit_Callback(hObject, eventdata, handles)
% hObject handle to stopbit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global stobit
val = get(handles.stopbit,'Value');
switch val
case 1
stobit = 1;
case 2
stobit = 1.5;
case 3
stobit = 2;
end
% Hints: contents = cellstr(get(hObject,'String')) returns stopbit contents as cell array
% contents{get(hObject,'Value')} returns selected item from stopbit
% --- Executes during object creation, after setting all properties.
function stopbit_CreateFcn(hObject, eventdata, handles)
% hObject handle to stopbit (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 parity.
function parity_Callback(hObject, eventdata, handles)
% hObject handle to parity (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global parit
val = get(handles.parity,'Value');
switch val
case 1
parit = 'None';
case 2
parit = 'Odd';
case 3
parit = 'Even';
case 4
parit = 'Mark';
case 5
parit = 'Space';
end
% Hints: contents = cellstr(get(hObject,'String')) returns parity contents as cell array
% contents{get(hObject,'Value')} returns selected item from parity
% --- Executes during object creation, after setting all properties.
function parity_CreateFcn(hObject, eventdata, handles)
% hObject handle to parity (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
评论0