function varargout = serial_receive(varargin)
% SERIAL_RECEIVE M-file for serial_receive.fig
% SERIAL_RECEIVE, by itself, creates a new SERIAL_RECEIVE or raises the existing
% singleton*.
%
% H = SERIAL_RECEIVE returns the handle to a new SERIAL_RECEIVE or the handle to
% the existing singleton*.
%
% SERIAL_RECEIVE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SERIAL_RECEIVE.M with the given input arguments.
%
% SERIAL_RECEIVE('Property','Value',...) creates a new SERIAL_RECEIVE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before serial_receive_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to serial_receive_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
% Copyright 2002-2003 The MathWorks, Inc.
% Edit the above text to modify the response to help serial_receive
% Last Modified by GUIDE v2.5 06-Jun-2007 10:46:44
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @serial_receive_OpeningFcn, ...
'gui_OutputFcn', @serial_receive_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_receive is made visible.
function serial_receive_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_receive (see VARARGIN)
% Choose default command line output for serial_receive
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes serial_receive wait for user response (see UIRESUME)
% uiwait(handles.figure1);
t=0:1/200:1;
global n
n=100000;%雷达威力范围100公里,P型显控坐标范围2*n,单位米,
x=n*cos(2*pi*t);
y=n*sin(2*pi*t);
set(handles.axes1,'xlim',[0 2*n],'ylim',[0 2*n])%,'HandleVisibility','off');%坐标轴范围
text(10,2*n*0.95,'\uparrow 北','FontSize',20,'HandleVisibility','off');
text(n+x(50)*1.05,n+y(50)*1.05,'0`','FontSize',8,'HandleVisibility','off');%角度初始化
text(n+x(75)*1.05,n+y(75)*1.05,'45`','FontSize',8,'HandleVisibility','off');
text(n+x(100)*1.05,n+y(100)*1.05,'90`','FontSize',8,'HandleVisibility','off');
text(n+x(125)*1.05,n+y(125)*1.05,'135`','FontSize',8,'HandleVisibility','off');
text(n+x(150)*1.05,n+y(150)*1.05,'180`','FontSize',8,'HandleVisibility','off');
text(n+x(175)*1.05,n+y(175)*1.05,'225`','FontSize',8,'HandleVisibility','off');
text(n+x(200)*1.02,n+y(200)*1.02,'270`','FontSize',8,'HandleVisibility','off');
text(n+x(25)*1.05,n+y(25)*1.05,'315`','FontSize',8,'HandleVisibility','off');
line('parent',handles.axes1,'xdata',x+n,'ydata',y+n,'LineWidth',0.5,'Color','k','HandleVisibility','off');%圆周,距离刻度初始化
text([n n],[2*n 0],'100','FontSize',8,'HandleVisibility','off');
line('parent',handles.axes1,'xdata',0.8*x+n,'ydata',0.8*y+n,'LineWidth',0.5,'Color','k','HandleVisibility','off');
text([n n],[1.8*n 0.2*n],'80','FontSize',8,'HandleVisibility','off');
line('parent',handles.axes1,'xdata',0.6*x+n,'ydata',0.6*y+n,'LineWidth',0.5,'Color','k','HandleVisibility','off');
text([n n],[1.6*n 0.4*n],'60','FontSize',8,'HandleVisibility','off');
line('parent',handles.axes1,'xdata',0.4*x+n,'ydata',0.4*y+n,'LineWidth',0.5,'Color','k','HandleVisibility','off');
text([n n],[1.4*n 0.6*n],'40','FontSize',8,'HandleVisibility','off');
line('parent',handles.axes1,'xdata',0.2*x+n,'ydata',0.2*y+n,'LineWidth',0.5,'Color','k','HandleVisibility','off');
text([n n],[1.2*n 0.8*n],'20','FontSize',8,'HandleVisibility','off');
line('parent',handles.axes1,'xdata',[0 2*n],'ydata',[n n],'LineWidth',0.5,'Color','k','HandleVisibility','off');
text(n,n,'0','FontSize',8,'HandleVisibility','off');
line('parent',handles.axes1,'xdata',[n n],'ydata',[0 2*n],'LineWidth',0.5,'Color','k','HandleVisibility','off');
%A型显控初始化
global h_line %扫掠线
global h_graph %p型显控,目标回波幅度
global h_pad %目标点迹
global h_serial %串口
global h_edit %文本栏
global f_stop_receive %退出标志
global f_stop_demo
global f_zoom
global f_pan
global d_obj_edit
d_obj_edit=zeros(10,4);
f_pan=0;
f_zoom=0;
h_line = line('parent',handles.axes1,'LineWidth',1,'Color',[0.502 0 1],'xdata',0,'ydata',0,'HandleVisibility','off');
h_graph = line('parent',handles.axes2,'LineWidth',1,'Color',[0.502 0 1],'xdata',0,'ydata',0,'HandleVisibility','off');
%h_pad = line('parent',handles.axes1,'markersize',5,'color','k','xdata',0,'ydata',0);
%h_pad2 = line('parent',handles.axes1,'markersize',5,'color','w','xdata',0,'ydata',0);
h_serial = serial('com2','baudrate',115200,'parity','none','databits',8,'stopbits',1 ,...
'inputbuffersize',424,'outputbuffersize',12,'ReadAsyncMode','continuous');%,...
%'BytesAvailableFcnMode','byte','BytesAvailableFcnCount',424,'BytesAvailableFcn',@receive);
h_edit = [handles.edit1 handles.edit2 handles.edit3 handles.edit4
handles.edit5 handles.edit6 handles.edit7 handles.edit8
handles.edit9 handles.edit10 handles.edit11 handles.edit12
handles.edit13 handles.edit14 handles.edit15 handles.edit16
handles.edit17 handles.edit18 handles.edit19 handles.edit20
handles.edit21 handles.edit22 handles.edit23 handles.edit24
handles.edit25 handles.edit26 handles.edit27 handles.edit28
handles.edit29 handles.edit30 handles.edit31 handles.edit32
handles.edit33 handles.edit34 handles.edit35 handles.edit36
handles.edit37 handles.edit38 handles.edit39 handles.edit40];
h_edit=h_edit';
% --- Outputs from this function are returned to the command line.
function varargout = serial_receive_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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)%接收
set(handles.pushbutton1,'foregroundcolor','r');
set(handles.pushbutton2,'foregroundcolor',[0 0 0]);
set(handles.pushbutton3,'foregroundcolor',[0 0 0]);
set(handles.pushbutton4,'foregroundcolor',[0 0 0]);
global h_serial
global f_stop_receive
global n
global h_line
global h_edit
global h_graph
global d_obj_edit
global d_obj_cmd%当前目标,在文本框第一行显示,作为命令字向下位机发送
f_stop_receive=1;
fopen(h_serial);
%接收主循环
while f_stop_receive
pause(0.000001)
if h_serial.BytesAvailable==424
N=350;
d_word=fread(h_serial,106,'float');
time=d_word(1);
d_obj=d_word(3:6);
pa=n*(cos(2*pi*time/N)+1);
pb=n*(sin(2*pi*time/N)+1);
set(h_line,'xdata',[pa n],'ydata',[pb n],'EraseMode','xor');