function varargout = Gui_Datadisplay(varargin)
% GUI_DATADISPLAY MATLAB code for Gui_Datadisplay.fig
% GUI_DATADISPLAY, by itself, creates a new GUI_DATADISPLAY or raises the existing
% singleton*.
%
% H = GUI_DATADISPLAY returns the handle to a new GUI_DATADISPLAY or the handle to
% the existing singleton*.
%
% GUI_DATADISPLAY('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI_DATADISPLAY.M with the given input arguments.
%
% GUI_DATADISPLAY('Property','Value',...) creates a new GUI_DATADISPLAY or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Gui_Datadisplay_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Gui_Datadisplay_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_Datadisplay
% Last Modified by GUIDE v2.5 17-Jun-2015 14:11:40
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Gui_Datadisplay_OpeningFcn, ...
'gui_OutputFcn', @Gui_Datadisplay_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_Datadisplay is made visible.
function Gui_Datadisplay_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_Datadisplay (see VARARGIN)
global COM;
global rate;
COM='COM7'
rate = 115200;
set(handles.ppCOM,'value', 7);
set(handles.ppBaudRates,'value',1);
set(handles.pbCloseSerial,'Enable','off');
% Choose default command line output for Gui_Datadisplay
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Gui_Datadisplay wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Gui_Datadisplay_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 Value_Callback(hObject, eventdata, handles)
% hObject handle to Value (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Value as text
% str2double(get(hObject,'String')) returns contents of Value as a double
% --- Executes during object creation, after setting all properties.
function Value_CreateFcn(hObject, eventdata, handles)
% hObject handle to Value (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% 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 pbOpenSerial.
function pbOpenSerial_Callback(hObject, eventdata, handles)
% hObject handle to pbOpenSerial (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
clc
instrreset
global s;
global rate;
global COM;
global out;
out=1;
s=serial(COM);
set(s,'BaudRate',rate);%%%Baud初始化
set(s,'DataBits',8);%%%设置数据长度
set(s,'StopBits',1);%%%设置停止位长度
set(s,'InputBufferSize',1024000);%%%设置输入缓冲区大小为1M
set(handles.pbOpenSerial,'Enable','off');
set(handles.pbCloseSerial,'Enable','on');
%串口事件回调设置
s.BytesAvailableFcnMode='terminator';
s.BytesAvailableFcnCount=10; %输入缓冲区存在10个字节触发回调函数
s.BytesAvailableFcn={@EveBytesAvailableFcn,handles};%回调函数的指定
fopen(s);%打开串口
global count;
count=1;
fprintf('ceshi_dakaichuankou\n');
%回调函数
function EveBytesAvailableFcn( t,event,handles )
global s;
global a;
global d;
global arrX;
global arrY;
global arrZ;
global count;
arrX=zeros([1,100]);
% arrY=[1,1000];
% arrZ=[1,1000];
% fprintf('Receive callback');
a=fscanf(s);
M=textscan(a,'%s%d%d%d','delimiter',' ');
% data = [data , '\n'];
[Name,x,y,z] = deal(M{:});
arrX(1,count) = x;
% arrY(1,count) = y;
% arrZ(1,count) = z;
a = strcat(a ,char(10), get(handles.editR,'string'));
set(handles.editR,'string',a);
set(handles.text4,'string',x);
plot(arrX);
hold on;
count=count+1;
if count==100
count=1;
clf;
end
% --- Executes on selection change in ppCOM.
function ppCOM_Callback(hObject, eventdata, handles)
% hObject handle to ppCOM (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns ppCOM contents as cell array
% contents{get(hObject,'Value')} returns selected item from ppCOM
global COM;
% COM=1;
rate=1;
val=get(hObject,'value');
switch val
case 1
COM='COM1';
fprintf('ceshi_COM=1\n');
case 2
COM='COM2';
case 3
COM='COM3';
case 4
COM='COM4';
case 5
COM='COM5';
case 6
COM='COM6';
case 7
COM='COM7';
fprintf('ceshi_COM=7\n');
case 8
COM='COM8';
case 9
COM='COM9';
end
% --- Executes during object creation, after setting all properties.
function ppCOM_CreateFcn(hObject, eventdata, handles)
% hObject handle to ppCOM (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 ppBaudRates.
function ppBaudRates_Callback(hObject, eventdata, handles)
% hObject handle to ppBaudRates (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns ppBaudRates contents as cell array
% contents{get(hObject,'Value')} returns selected item from ppBaudRates
global rate;
val=get(hObject,'value');
switch val
case 1
rate=115200;
case 2
rate=9600;
end
% --- Executes during object creation, after setting all properties.
function ppBaudRates_CreateFcn(hObject, eventdata, handles)
% hObject handle to ppBaudRates (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,'defaultUicontro
- 1
- 2
- 3
- 4
- 5
- 6
前往页