说明
上半部分为串口助手,下半部分为雷达测试指令。
代码目录下有一张名为icon的图片作为图标。
雷达发波指令
scan stop\r\n
ant_calib_new X-30.0Y0.0 1 10 2.5 3.5 0 0\r\n
ant_calib_new X-25.0Y0.0 1 10 2.5 3.5 0 0\r\n
XY:转台角度;
1/2:高速模式(HV)、低速模式(LV);
10:每次跑10帧;
2.5 3.5 0 0:搜索参数;
接收的数据类似于:
ant_calib_new X0Y-16 1 10 2.5 3.5 0 0
0.000000 0.12086 -49.236392 0.08948 0.000000 0.13483 -16.858400 0.01814 45.000000 0.00049 28.201627 0.09354 121.429557 0.10864 -22.659351 0.01188 -66.929580 0.05257 -173.659790 0.04504 -31.759481 0.08377 175.815109 0.00645 -41.423660 0.00784 -70.484123 0.10719 145.713119 0.04327 -47.862403 0.01224 tarRid 15 tarR 3.02 noiP 0.000002 waveT 0
-1.302060 0.11823 -50.194427 0.09308 -1.245369 0.12921 -16.620761 0.01865 45.000000 0.00049 28.072484 0.08930 121.429557 0.10864 -23.600191 0.01205 -67.833656 0.05188 -173.659790 0.04504 -32.592582 0.07999 178.531265 0.00581 -39.805572 0.00838 -71.565048 0.10315 144.462326 0.04065 -48.012786 0.01105 tarRid 15 tarR 3.02 noiP 0.000002 waveT 0
0.654915 0.11684 -49.236392 0.08948 0.000000 0.12915 -15.255105 0.01785 45.000000 0.00049 29.419071 0.08894 123.310623 0.10706 -22.858755 0.01169 -66.929580 0.05257 -173.659790 0.04504 -31.097307 0.08260 178.602951 0.00642 -37.874980 0.00793 -70.016899 0.10243 147.528808 0.04150 -48.012786 0.01105 tarRid 15 tarR 3.02 noiP 0.000002 waveT 0
-0.658491 0.11551 -49.236392 0.08948 -1.245369 0.12921 -16.534832 0.01700 36.869895 0.00038 28.072484 0.08930 120.963752 0.10168 -25.144783 0.01118 -66.929580 0.05257 -173.659790 0.04504 -31.759481 0.08377 174.427780 0.00647 -41.423660 0.00784 -71.454223 0.10196 146.309936 0.03888 -46.548152 0.01045 tarRid 15 tarR 3.02 noiP 0.000002 waveT 0
0.331022 0.11417 -48.179824 0.08926 1.245369 0.12921 -15.478633 0.01735 45.000000 0.00049 30.256433 0.08908 122.152290 0.10431 -21.898197 0.01153 -66.540969 0.05093 -172.476181 0.04361 -29.744878 0.08034 -178.567962 0.00611 -37.874980 0.00793 -69.239028 0.10213 147.528808 0.04150 -46.548152 0.01045 tarRid 15 tarR 3.02 noiP 0.000001 waveT 0
0.993669 0.11420 -48.179824 0.08926 1.245369 0.12921 -14.237276 0.01823 36.869895 0.00038 30.638578 0.08709 124.077186 0.10284 -23.334047 0.01177 -66.929580 0.05257 -172.476181 0.04361 -30.425777 0.08145 178.636138 0.00673 -37.874980 0.00793 -69.775138 0.10010 149.420761 0.03986 -46.548152 0.01045 tarRid 15 tarR 3.02 noiP 0.000002 waveT 0
-0.993669 0.11420 -49.316028 0.08621 0.000000 0.12360 -17.102739 0.01764 36.869895 0.00038 28.943920 0.08680 122.152290 0.10431 -23.198595 0.01084 -67.833656 0.05188 -173.541168 0.04341 -30.827665 0.07954 175.710830 0.00614 -39.472454 0.00740 -70.346168 0.10201 147.528808 0.04150 -46.548152 0.01045 tarRid 15 tarR 3.02 noiP 0.000002 waveT 0
-0.658491 0.11551 -48.239696 0.08600 0.000000 0.12360 -15.478633 0.01735 44.999992 0.00027 28.274862 0.08570 122.152290 0.10431 -23.600191 0.01205 -67.833656 0.05188 -173.418045 0.04181 -31.504266 0.08069 178.567962 0.00611 -39.805572 0.00838 -70.559967 0.10042 146.309936 0.03888 -46.548152 0.01045 tarRid 15 tarR 3.02 noiP 0.000002 waveT 0
-0.331022 0.11417 -49.236392 0.08948 0.000000 0.12360 -17.102739 0.01764 44.999992 0.00027 28.761159 0.08781 122.905235 0.10010 -22.988710 0.01103 -66.929580 0.05257 -173.418045 0.04181 -31.239213 0.07767 178.567962 0.00611 -39.472454 0.00740 -69.775138 0.10010 147.528808 0.04150 -46.548152 0.01045 tarRid 15 tarR 3.02 noiP 0.000002 waveT 0
0.337461 0.11025 -48.239696 0.08600 1.272877 0.12366 -16.782644 0.01652 36.869895 0.00038 30.504354 0.08551 122.905235 0.10010 -21.305780 0.01099 -65.637542 0.05165 -172.476181 0.04361 -29.054605 0.07925 -178.636138 0.00673 -36.384349 0.00850 -68.860176 0.09866 148.240509 0.03723 -45.000000 0.00989 tarRid 15 tarR 3.02 noiP 0.000001 waveT 0
<EOF>
ant_calib_new X0Y-15 1 10 2.5 3.5 0 0
15.018359 0.10999 -16.927505 0.03528 21.425298 0.10989 7.594632 0.01398 33.690063 0.00079 34.592289 0.05799 147.955307 0.09111 -16.699249 0.02037 -42.337001 0.05655 -167.005371 0.01086 -23.782026 0.06343 147.380752 0.03025 -0.954701 0.01374 -76.883567 0.04267 159.537719 0.07803 -53.130100 0.00153 tarRid 15 tarR 3.02 noiP 0.000002 waveT 0
14.691963 0.10965 -16.927505 0.03528 22.306201 0.10846 6.441594 0.01485 38.659812 0.00063 34.359378 0.05376 148.781600 0.09088 -15.945407 0.02022 -41.633541 0.05531 -167.905242 0.01251 -24.590116 0.06424 147.188629 0.03119 0.939203 0.01420 -73.979705 0.04212 160.559967 0.07935 -53.130100 0.00153 tarRid 15 tarR 3.02 noiP 0.000002 waveT 0
15.106301 0.10874 -16.927505 0.03528 23.198595 0.10709 5.617577 0.01433 38.659812 0.00063 36.869895 0.05724 149.036239 0.08768 -16.389541 0.01917 -41.633541 0.05531 -167.905242 0.01251 -24.962789 0.06245 147.578933 0.02932 1.877948 0.01421 -74.649864 0.04268 160.426864 0.07831 -52.125019 0.00198 tarRid 15 tarR 3.02 noiP 0.000002 waveT 0
16.135580 0.10451 -16.927505 0.03528 23.749494 0.10245 5.710622 0.01387 30.963750 0.00052 37.539432 0.05476 150.068481 0.08850 -14.036246 0.01874 -40.292148 0.05550 -167.905242 0.01251 -23.782026 0.06343 149.369995 0.02976 1.877948 0.01421 -73.827842 0.04136 161.565048 0.07725 -50.906139 0.00162 tarRid 15 tarR 3.02 noiP 0.000002 waveT 0
16.566074 0.10366 -14.620860 0.03448 23.749494 0.10245 7.471573 0.01444 30.963750 0.00052 37.060405 0.05521 150.908813 0.08837 -15.037812 0.01836 -40.292148 0.05550 -164.054595 0.01294 -23.782026 0.06343 150.255111 0.03000 2.815568 0.01423 -73.827842 0.04136 162.194656 0.07898 -48.814071 0.00172 tarRid 15 tarR 3.02 noiP 0.000002 waveT 0
14.620886 0.10561 -16.927505 0.03528 22.456941 0.10049 6.546283 0.01438 33.690063 0.00079 36.280254 0.05187 149.688781 0.08650 -14.826472 0.01888 -40.914382 0.05411 -167.905242 0.01251 -24.145540 0.06165 147.783447 0.02840 0.954701 0.01374 -74.207595 0.04038 160.292007 0.07729 -48.814071 0.00172 tarRid 15 tarR 3.02 noiP 0.000001 waveT 0
16.868654 0.10007 -14.620860 0.03448 23.470991 0.10475 8.820379 0.01314 26.565052 0.00069 37.064449 0.05294 151.056076 0.08680 -15.037812 0.01836 -39.559673 0.05432 -167.905242 0.01251 -22.963777 0.06265 150.018356 0.03093 2.815568 0.01423 -73.141601 0.04082 162.718490 0.07625 -49.085613 0.00150 tarRid 15 tarR 3.02 noiP 0.000002 waveT 0
14.886263 0.10196 -16.927505 0.03528 22.190288 0.10280 6.881735 0.01302 30.963750 0.00052 36.098281 0.05385 149.167053 0.08610 -16.389541 0.01917 -40.179233 0.05293 -167.905242 0.01251 -24.962789 0.06245 148.477813 0.02953 1.877948 0.01421 -73.515541 0.03984 162.208786 0.07555 -48.814071 0.00172 tarRid 15 tarR 3.02 noiP 0.000002 waveT 0
16.665760 0.10246 -14.620860 0.03448 24.676868 0.10120 6.654402 0.01392 30.963750 0.00052 38.585395 0.05516 150.871170 0.08579 -13.431014 0.01810 -40.179233 0.05293 -167.005371 0.01086 -24.145540 0.06165 148.815017 0.03011 3.751758 0.01426 -72.979476 0.04007 162.454269 0.07761 -48.814071 0.00172 tarRid 15 tarR 3.02 noiP 0.000002 waveT 0
16.665760 0.10246 -14.620860 0.03448 24.325569 0.09793 8.530760 0.01404 33.690063 0.00079 38.047039 0.05206 151.205993 0.08524 -14.826472 0.01888 -39.559673 0.05432 -165.465530 0.01187 -22.963777 0.06265 151.132827 0.03026 3.751758 0.01426 -72.103866 0.03882 163.657119 0.07328 -47.290611 0.00119 tarRid 15 tarR 3.02 noiP 0.000002 waveT 0
<EOF>
K:帧数
M:配置波形数
N:接收通道数(虚拟后)
P_((k,m,n)):接收通道的相位(单位,deg)
A_((k,m,n)):接收通道的幅度(2D-FFT后目标幅度值平方)
tarRid((k,m)):目标的距离单元(从0开始)
tarR((k,m)):目标的距离(单位:米)
noiR(k,m)):噪声幅度(2D-FFT后噪声幅度值平方)
waveT((k,m)):波形类型
打印日志:
--------log--------
时间:31-Aug-2023 17:23:55
SingleTarget 起始角-75 终止角75 步进角30 角度差0 rcs1:10 rcs2:15
FlagINFO SingleTarget -75 75 30 0 10 15
--------log--------
参考代码:https://gitee.com/xsy754384522/matlab_-xsy
推荐继续学习app designer:https://github.com/wdther/APPdesignerPractice
代码
classdef Serial_app < matlab.apps.AppBase
properties (Access = public)
MySerialUIFigure matlab.ui.Figure
Serial_Lamp matlab.ui.control.Lamp
Serial_Switch matlab.ui.control.Switch
Label_10 matlab.ui.control.Label
Signal_select matlab.ui.control.DropDown
Label_5 matlab.ui.control.Label
Serial_check_bits matlab.ui.control.DropDown
Label_4 matlab.ui.control.Label
Serial_stop_bits matlab.ui.control.DropDown
Label_3 matlab.ui.control.Label
Serial_data_bits matlab.ui.control.DropDown
Label_2 matlab.ui.control.Label
Serial_baud_rate matlab.ui.control.DropDown
Label matlab.ui.control.Label
Serial_port_number matlab.ui.control.DropDown
filename matlab.ui.control.EditField
Label_11 matlab.ui.control.Label
Angle_difference matlab.ui.control.Spinner
SpinnerLabel matlab.ui.control.Label
step_angle matlab.ui.control.Spinner
Label_8 matlab.ui.control.Label
end_angle matlab.ui.control.Spinner
Label_9 matlab.ui.control.Label
Start_angle matlab.ui.control.Spinner
Label_7 matlab.ui.control.Label
RCS2Spinner matlab.ui.control.Spinner
RCS2SpinnerLabel matlab.ui.control.Label
RCS1Spinner matlab.ui.control.Spinner
RCS1SpinnerLabel matlab.ui.control.Label
Clockwise matlab.ui.control.DropDown
Single_Multi matlab.ui.control.DropDown
list_of_messages matlab.ui.control.TextArea
FilePathButton matlab.ui.control.Button
FilePath matlab.ui.control.EditField
over_button matlab.ui.control.Button
radar_pause matlab.ui.control.Button
Clear_message_display matlab.ui.control.Button
radar_start matlab.ui.control.Button
TX_Text_hex matlab.ui.control.TextArea
TextArea matlab.ui.control.TextArea
Hex_send matlab.ui.control.CheckBox
Hex_disp matlab.ui.control.CheckBox
Button_clr_receive matlab.ui.control.Button
Button_save matlab.ui.control.Button
Label_6 matlab.ui.control.Label
RX_Text matlab.ui.control.TextArea
Button_clr_send matlab.ui.control.Button
Button_send matlab.ui.control.Button
TextArea_2Label matlab.ui.control.Label
TX_Text matlab.ui.control.TextArea
end
properties (Access = private)
SerialObject
Str_Data
Hex_Data
Message_display
StartAngle
StopAngle
StepAngle
realStepAngle
NowAngle
SendQuit
SignalFlag
FileName
RadarFid
pause_TIME
end
methods (Access = private)
function SerialConfig(app)
app.Serial_port_number.Items=seriallist("all");
if(strcmp(app.Serial_Switch.Value,'开启'))
delete(app.SerialObject);
app.Serial_Lamp.Color=[0,1,0];
try
app.SerialObject=serialport(app.Serial_port_number.Value , str2double(app.Serial_baud_rate.Value) , ...
"DataBits",str2double(app.Serial_data_bits.Value) , ...
"StopBits",str2double(app.Serial_stop_bits.Value) , ...
"Parity",app.Serial_check_bits.Value);
configureTerminator(app.SerialObject,'LF');
configureCallback(app.SerialObject,"terminator",@SerialCallback);
catch
msgbox('串口打开失败');
delete(app.SerialObject);
app.Serial_Lamp.Color=[0.65,0.65,0.65];
app.Serial_Switch.Value = '关闭';
end
elseif(strcmp(app.Serial_Switch.Value,'关闭'))
delete(app.SerialObject);
app.Serial_Lamp.Color=[0.65,0.65,0.65];
end
function SerialCallback(src,event)
if(app.SignalFlag)
radar_receive_func(app)
else
Serial_receive_func(app);
end
end
end
function Serial_receive_func(app)
app.TextArea.Value=[app.TextArea.Value;readline(app.SerialObject)];
app.Str_Data=app.TextArea.Value;
app.Str_Data(1)=[];
app.Hex_Data='';
num_cell=length(app.Str_Data);
for i=1:num_cell
temp=cellstr(dec2hex(abs(app.Str_Data{i})));
len=length(temp);
for j=1:len
if(length(temp{j})==2)
app.Hex_Data=strcat(app.Hex_Data,32,temp{j});
else
app.Hex_Data=strcat(app.Hex_Data,32,'0',temp{j});
end
end
app.Hex_Data=strcat(app.Hex_Data,32,'0A');
end
if(app.Hex_disp.Value==1)
app.RX_Text.Value=app.Hex_Data;
else
app.RX_Text.Value=app.Str_Data;
end
end
function radar_receive_func(app)
radar_receive_data1=readline(app.SerialObject);
app.RadarFid=fopen(app.FileName,'a');
fprintf(app.RadarFid,'%s\n',radar_receive_data1);
fclose(app.RadarFid);
end
end
methods (Access = private)
function startupFcn(app)
app.Serial_port_number.Items=seriallist("all");
app.StartAngle = app.Start_angle.Value;
app.StepAngle = app.step_angle.Value;
app.StopAngle = app.end_angle.Value;
app.pause_TIME=0.35;
if(strcmp(app.Signal_select.Value,'雷达信号'))
app.SignalFlag=1;
else
app.SignalFlag=0;
end
end
function Serial_port_numberDropDownOpening(app, event)
SerialConfig(app);
end
function Serial_port_numberValueChanged(app, event)
SerialConfig(app);
end
function Serial_baud_rateValueChanged(app, event)
SerialConfig(app);
end
function Serial_data_bitsValueChanged(app, event)
SerialConfig(app);
end
function Serial_stop_bitsValueChanged(app, event)
SerialConfig(app);
end
function Serial_check_bitsValueChanged(app, event)
SerialConfig(app);
end
function Serial_SwitchValueChanged(app, event)
SerialConfig(app);
end
function Hex_dispValueChanged(app, event)
if(app.Hex_disp.Value==1)
app.RX_Text.Value=app.Hex_Data;
else
app.RX_Text.Value=app.Str_Data;
end
end
function Button_clr_receivePushed(app, event)
app.RX_Text.Value='';
app.TextArea.Value='';
app.Str_Data='';
app.Hex_Data='';
end
function Button_savePushed(app, event)
context=app.RX_Text.Value;
arr=length(context);
if(app.Hex_disp.Value==0)
fid=fopen('data.txt','w+');
for i=1:arr
fprintf(fid,'%s\r\n',context{i});
end
fclose(fid);
elseif(app.Hex_disp.Value==1)
fid=fopen('data_hex.txt','w+');
fprintf(fid,'%s\r\n',context{1});
fclose(fid);
end
end
function Button_clr_sendPushed(app, event)
app.TX_Text.Value='';
app.TX_Text_hex.Value='';
end
function Button_sendPushed(app, event)
if(strcmp(app.Serial_Switch.Value,'开启'))
if(app.Hex_send.Value==0)
str=app.TX_Text.Value;
cell_num=length(str);
if(cell_num==1)
if((length(abs(str{1})))~=0)
write(app.SerialObject,abs(str{1}),"uint8");
end
else
for i=1:cell_num-1
writeline(app.SerialObject,sprintf('%s\r',str{i}));
end
if(~isempty(abs(str{cell_num})))
write(app.SerialObject,abs(str{cell_num}),"uint8");
end
end
else
n=length(app.TX_Text_hex.Value);
if(n==1)
context=hex2dec(strsplit(app.TX_Text_hex.Value{1}));
len=length(context);
uint8 send_flag;
send_flag=1;
if(len==0)
msgbox('发送内容不能为空')
else
for i=1:len
if(context(i)>255)
send_flag=0;
break;
end
end
if(send_flag)
write(app.SerialObject,context,"uint8");
else
msgbox('请输入正确的16进制数据');
end
end
else
msgbox('16进制发送请用 0D 0A 代替回车换行');
end
end
end
end
function Hex_sendValueChanged(app, event)
if app.Hex_send.Value==1
app.TX_Text_hex.Visible=1;
app.TX_Text.Visible=0;
temp=app.TX_Text.Value;
string s;
s ='';
m=length(temp);
if(m>1)
for i=1:m-1
x=cellstr(dec2hex(abs(temp{i})));
n=length(x);
if(n~=0)
for j=1:n
s=strcat(s,32,x{j});
end
s=strcat(s,32,'0D',32,'0A');
end
end
x=cellstr(dec2hex(abs(temp{m})));
n=length(x);
flag=length(dec2hex(abs(temp{m})));
if(flag)
for j=1:n
s=strcat(s,32,x{j});
end
end
s(1)=[];
elseif(m==1)
if(~isempty(abs(temp{1})))
x=cellstr(dec2hex(abs(temp{1})));
n=length(x);
for j=1:n
s=strcat(s,32,x{j});
end
s(1)=[];
end
end
app.TX_Text_hex.Value=s;
else
app.TX_Text_hex.Visible=0;
app.TX_Text.Visible=1;
hex_temp=app.TX_Text_hex.Value;
hex_temp_length=length(hex_temp);
if(hex_temp_length==1)
try
temp=(char(hex2dec(strsplit(hex_temp{1}))))';
ugrp=abs(temp);
v=length(ugrp);
if((v>=2)&&(ugrp(v)==10)&&(ugrp(v-1)==13))
app.TX_Text.Value=temp;
app.TX_Text.Value{end+1}='';
else
app.TX_Text.Value=temp;
end
catch
msgbox('请输入正确的16进制数据');
end
elseif(hex_temp_length>1)
msgbox('16进制发送请用 0D 0A 代替回车换行');
app.Hex_send.Value=1;
app.TX_Text_hex.Visible=0;
app.TX_Text.Visible=0;
end
end
end
function Start_angleValueChanged(app, event)
app.StartAngle = app.Start_angle.Value;
end
function step_angleValueChanged(app, event)
app.StepAngle = app.step_angle.Value;
end
function end_angleValueChanged(app, event)
app.StopAngle = app.end_angle.Value;
end
function FilePathButtonPushed(app, event)
FilePathtemp = uigetdir;
if(FilePathtemp)
app.FilePath.Value = FilePathtemp ;
end
end
function radar_startButtonPushed(app, event)
if(strcmp(app.Serial_Switch.Value,'开启'))
app.SendQuit=0;
try
app.Single_Multi.Enable=0;
app.Clockwise.Enable=0;
app.RCS1Spinner.Enable=0;
app.RCS2Spinner.Enable=0;
app.Start_angle.Enable=0;
app.step_angle.Enable=0;
app.end_angle.Enable=0;
app.Angle_difference.Enable=0;
app.FileName=fullfile(app.FilePath.Value,strcat(app.filename.Value,'.txt'));
if ~isempty(dir(app.FileName))
delete(app.FileName);
end
app.RadarFid=fopen(app.FileName,'a');
fprintf(app.RadarFid,'--------log--------\n');
fprintf(app.RadarFid,'时间:%s\n',datestr(now));
fprintf(app.RadarFid,'%s 起始角%d 终止角%d 步进角%d 角度差%d rcs1:%d rcs2:%d\r\n',...
app.Single_Multi.Value,...
app.Start_angle.Value,...
app.end_angle.Value,...
app.step_angle.Value,...
app.Angle_difference.Value,...
app.RCS1Spinner.Value,...
app.RCS2Spinner.Value);
fprintf(app.RadarFid,'FlagINFO %s %d %d %d %d %d %d\r\n',...
app.Single_Multi.Value,...
app.Start_angle.Value,...
app.end_angle.Value,...
app.step_angle.Value,...
app.Angle_difference.Value,...
app.RCS1Spinner.Value,...
app.RCS2Spinner.Value);
fprintf(app.RadarFid,'--------log--------\n\n');
fclose(app.RadarFid);
write(app.SerialObject,sprintf('scan stop\r\n'),"string");
if(strcmp(app.Clockwise.Value,'负坐标系'))
if(app.StartAngle<0)
direction = 0 ;
else
direction = 1 ;
end
else
if(app.StartAngle<0)
direction = 1 ;
else
direction = 0 ;
end
end
write(app.SerialObject,sprintf('rotary_cailb %d %d \r\n',direction,app.StartAngle),"string");
app.Message_display=strcat(app.Message_display,'----开始----');
app.list_of_messages.Value=app.Message_display;
pause_time=round(app.pause_TIME*abs(app.StartAngle));
while((pause_time>0)&(strcmp(app.Serial_Switch.Value,'开启')))
app.Message_display=strcat(app.Message_display,'延时还剩',num2str(pause_time),'秒。。。');
app.list_of_messages.Value=app.Message_display;
pause(1);
pause_time=pause_time-1;
if(app.SendQuit)
return;
end
end
app.NowAngle=app.StartAngle;
app.Message_display=strcat(app.Message_display,'!!!延时结束!!!');
app.Message_display=strcat(app.Message_display,'----当前角度',num2str(app.NowAngle),'----');
app.list_of_messages.Value=app.Message_display;
write(app.SerialObject,sprintf('ant_calib_new X%d.0Y0.0 1 50 2.5 3.5 0 0\r\n',app.NowAngle),"string");
if(strcmp(app.Clockwise.Value,'负坐标系'))
if(app.StartAngle>app.StopAngle)
direction = 0 ;
app.realStepAngle=-app.StepAngle;
else
direction = 1 ;
app.realStepAngle=app.StepAngle;
end
else
if(app.StartAngle>app.StopAngle)
direction = 1 ;
app.realStepAngle=-app.StepAngle;
else
direction = 0 ;
app.realStepAngle=app.StepAngle;
end
end
pause_time=app.pause_TIME*abs(app.StepAngle);
while((abs(app.NowAngle-app.StopAngle)>=abs(app.StepAngle))&(strcmp(app.Serial_Switch.Value,'开启')))
write(app.SerialObject,sprintf('rotary_cailb %d %d \r\n',direction,app.realStepAngle),"string");
pause(pause_time);
app.NowAngle=app.NowAngle+app.realStepAngle;
app.Message_display=strcat(app.Message_display,'----当前角度',num2str(app.NowAngle),'----');
app.list_of_messages.Value=app.Message_display;
write(app.SerialObject,sprintf('ant_calib_new X%d.0Y0.0 1 50 2.5 3.5 0 0\r\n',app.NowAngle),"string");
if(app.SendQuit)
return;
end
end
app.Message_display=strcat(app.Message_display,'----结束----');
app.list_of_messages.Value=app.Message_display;
catch
end
try
app.Single_Multi.Enable=1;
app.Clockwise.Enable=1;
app.RCS1Spinner.Enable=1;
app.RCS2Spinner.Enable=1;
app.Start_angle.Enable=1;
app.step_angle.Enable=1;
app.end_angle.Enable=1;
app.Angle_difference.Enable=1;
catch
end
end
end
function radar_pauseButtonPushed(app, event)
str=app.radar_pause.Text;
if(strcmp(str,'暂停'))
app.radar_pause.Text='继续';
uiwait;
else
app.radar_pause.Text='暂停';
uiresume;
end
end
function over_buttonButtonPushed(app, event)
app.SendQuit=1;
try
app.Single_Multi.Enable=1;
app.Clockwise.Enable=1;
app.RCS1Spinner.Enable=1;
app.RCS2Spinner.Enable=1;
app.Start_angle.Enable=1;
app.step_angle.Enable=1;
app.end_angle.Enable=1;
app.Angle_difference.Enable=1;
catch
end
end
function Clear_message_displayButtonPushed(app, event)
app.Message_display='';
app.list_of_messages.Value='';
end
function Signal_selectValueChanged(app, event)
value = app.Signal_select.Value;
if(strcmp(value,'雷达信号'))
app.SignalFlag=1;
else
app.SignalFlag=0;
end
end
end
methods (Access = private)
function createComponents(app)
app.MySerialUIFigure = uifigure('Visible', 'off');
app.MySerialUIFigure.Color = [0.8 0.902 0.949];
app.MySerialUIFigure.Position = [100 100 700 700];
app.MySerialUIFigure.Name = 'MySerial';
app.MySerialUIFigure.Icon = 'icon.jpg';
app.MySerialUIFigure.Scrollable = 'on';
app.TX_Text = uitextarea(app.MySerialUIFigure);
app.TX_Text.Position = [330 375 350 125];
app.TextArea_2Label = uilabel(app.MySerialUIFigure);
app.TextArea_2Label.HorizontalAlignment = 'center';
app.TextArea_2Label.Position = [253 475 75 25];
app.TextArea_2Label.Text = '发送数据';
app.Button_send = uibutton(app.MySerialUIFigure, 'push');
app.Button_send.ButtonPushedFcn = createCallbackFcn(app, @Button_sendPushed, true);
app.Button_send.Position = [475 340 75 25];
app.Button_send.Text = '发送数据';
app.Button_clr_send = uibutton(app.MySerialUIFigure, 'push');
app.Button_clr_send.ButtonPushedFcn = createCallbackFcn(app, @Button_clr_sendPushed, true);
app.Button_clr_send.Position = [605 340 75 25];
app.Button_clr_send.Text = '清除发送';
app.RX_Text = uitextarea(app.MySerialUIFigure);
app.RX_Text.Position = [330 556 350 125];
app.Label_6 = uilabel(app.MySerialUIFigure);
app.Label_6.HorizontalAlignment = 'center';
app.Label_6.Position = [253 656 75 25];
app.Label_6.Text = '接收数据';
app.Button_save = uibutton(app.MySerialUIFigure, 'push');
app.Button_save.ButtonPushedFcn = createCallbackFcn(app, @Button_savePushed, true);
app.Button_save.Position = [475 525 75 25];
app.Button_save.Text = '保存数据';
app.Button_clr_receive = uibutton(app.MySerialUIFigure, 'push');
app.Button_clr_receive.ButtonPushedFcn = createCallbackFcn(app, @Button_clr_receivePushed, true);
app.Button_clr_receive.Position = [605 525 75 25];
app.Button_clr_receive.Text = '清除接收';
app.Hex_disp = uicheckbox(app.MySerialUIFigure);
app.Hex_disp.ValueChangedFcn = createCallbackFcn(app, @Hex_dispValueChanged, true);
app.Hex_disp.Text = 'Hex显示';
app.Hex_disp.Position = [263 556 75 50];
app.Hex_send = uicheckbox(app.MySerialUIFigure);
app.Hex_send.ValueChangedFcn = createCallbackFcn(app, @Hex_sendValueChanged, true);
app.Hex_send.Text = 'Hex显示';
app.Hex_send.Position = [263 374 75 50];
app.TextArea = uitextarea(app.MySerialUIFigure);
app.TextArea.Visible = 'off';
app.TextArea.Position = [330 556 350 125];
app.TX_Text_hex = uitextarea(app.MySerialUIFigure);
app.TX_Text_hex.Position = [330 374 350 126];
app.radar_start = uibutton(app.MySerialUIFigure, 'push');
app.radar_start.ButtonPushedFcn = createCallbackFcn(app, @radar_startButtonPushed, true);
app.radar_start.Position = [40 58 100 30];
app.radar_start.Text = '开始';
app.Clear_message_display = uibutton(app.MySerialUIFigure, 'push');
app.Clear_message_display.ButtonPushedFcn = createCallbackFcn(app, @Clear_message_displayButtonPushed, true);
app.Clear_message_display.Position = [180 58 100 30];
app.Clear_message_display.Text = '清除显示';
app.radar_pause = uibutton(app.MySerialUIFigure, 'push');
app.radar_pause.ButtonPushedFcn = createCallbackFcn(app, @radar_pauseButtonPushed, true);
app.radar_pause.Position = [40 20 100 30];
app.radar_pause.Text = '暂停';
app.over_button = uibutton(app.MySerialUIFigure, 'push');
app.over_button.ButtonPushedFcn = createCallbackFcn(app, @over_buttonButtonPushed, true);
app.over_button.Position = [180 20 100 30];
app.over_button.Text = '结束';
app.FilePath = uieditfield(app.MySerialUIFigure, 'text');
app.FilePath.Position = [330 20 240 30];
app.FilePath.Value = 'C:\Users\Public\Downloads';
app.FilePathButton = uibutton(app.MySerialUIFigure, 'push');
app.FilePathButton.ButtonPushedFcn = createCallbackFcn(app, @FilePathButtonPushed, true);
app.FilePathButton.Position = [600 20 80 30];
app.FilePathButton.Text = '保存路径';
app.list_of_messages = uitextarea(app.MySerialUIFigure);
app.list_of_messages.Position = [330 65 350 250];
app.Single_Multi = uidropdown(app.MySerialUIFigure);
app.Single_Multi.Items = {'SingleTarget', 'MultiTarget'};
app.Single_Multi.Position = [40 289 100 25];
app.Single_Multi.Value = 'SingleTarget';
app.Clockwise = uidropdown(app.MySerialUIFigure);
app.Clockwise.Items = {'负坐标系', '正坐标系'};
app.Clockwise.Position = [180 289 100 25];
app.Clockwise.Value = '负坐标系';
app.RCS1SpinnerLabel = uilabel(app.MySerialUIFigure);
app.RCS1SpinnerLabel.HorizontalAlignment = 'right';
app.RCS1SpinnerLabel.Position = [19 246 33 26];
app.RCS1SpinnerLabel.Text = 'RCS1';
app.RCS1Spinner = uispinner(app.MySerialUIFigure);
app.RCS1Spinner.Limits = [-100 100];
app.RCS1Spinner.Position = [65 246 75 25];
app.RCS2SpinnerLabel = uilabel(app.MySerialUIFigure);
app.RCS2SpinnerLabel.HorizontalAlignment = 'right';
app.RCS2SpinnerLabel.Position = [157 245 38 26];
app.RCS2SpinnerLabel.Text = 'RCS2';
app.RCS2Spinner = uispinner(app.MySerialUIFigure);
app.RCS2Spinner.Limits = [-100 100];
app.RCS2Spinner.Position = [205 246 75 25];
app.Label_7 = uilabel(app.MySerialUIFigure);
app.Label_7.HorizontalAlignment = 'right';
app.Label_7.Position = [13 198 38 26];
app.Label_7.Text = '起始角';
app.Start_angle = uispinner(app.MySerialUIFigure);
app.Start_angle.Limits = [-180 180];
app.Start_angle.ValueChangedFcn = createCallbackFcn(app, @Start_angleValueChanged, true);
app.Start_angle.Position = [65 197 75 25];
app.Label_9 = uilabel(app.MySerialUIFigure);
app.Label_9.HorizontalAlignment = 'right';
app.Label_9.Position = [152 198 43 26];
app.Label_9.Text = '终止角';
app.end_angle = uispinner(app.MySerialUIFigure);
app.end_angle.Limits = [-180 180];
app.end_angle.ValueChangedFcn = createCallbackFcn(app, @end_angleValueChanged, true);
app.end_angle.Position = [205 197 75 25];
app.Label_8 = uilabel(app.MySerialUIFigure);
app.Label_8.HorizontalAlignment = 'right';
app.Label_8.Position = [0 147 51 26];
app.Label_8.Text = '步进角';
app.step_angle = uispinner(app.MySerialUIFigure);
app.step_angle.Limits = [1 180];
app.step_angle.ValueChangedFcn = createCallbackFcn(app, @step_angleValueChanged, true);
app.step_angle.Position = [65 148 75 25];
app.step_angle.Value = 5;
app.SpinnerLabel = uilabel(app.MySerialUIFigure);
app.SpinnerLabel.HorizontalAlignment = 'right';
app.SpinnerLabel.Position = [152 147 43 26];
app.SpinnerLabel.Text = '角度差';
app.Angle_difference = uispinner(app.MySerialUIFigure);
app.Angle_difference.Limits = [-90 90];
app.Angle_difference.Position = [205 148 75 25];
app.Label_11 = uilabel(app.MySerialUIFigure);
app.Label_11.HorizontalAlignment = 'right';
app.Label_11.Position = [5 99 46 26];
app.Label_11.Text = '文件名';
app.filename = uieditfield(app.MySerialUIFigure, 'text');
app.filename.Position = [65 100 75 25];
app.filename.Value = 'group1';
app.Serial_port_number = uidropdown(app.MySerialUIFigure);
app.Serial_port_number.Items = {'com1', 'com2', 'com3', 'com4'};
app.Serial_port_number.DropDownOpeningFcn = createCallbackFcn(app, @Serial_port_numberDropDownOpening, true);
app.Serial_port_number.ValueChangedFcn = createCallbackFcn(app, @Serial_port_numberValueChanged, true);
app.Serial_port_number.Position = [100 656 100 25];
app.Serial_port_number.Value = 'com1';
app.Label = uilabel(app.MySerialUIFigure);
app.Label.HorizontalAlignment = 'right';
app.Label.Position = [13 656 68 28];
app.Label.Text = '串口号';
app.Serial_baud_rate = uidropdown(app.MySerialUIFigure);
app.Serial_baud_rate.Items = {'9600', '115200', '3000000'};
app.Serial_baud_rate.ValueChangedFcn = createCallbackFcn(app, @Serial_baud_rateValueChanged, true);
app.Serial_baud_rate.Position = [100 609 100 25];
app.Serial_baud_rate.Value = '9600';
app.Label_2 = uilabel(app.MySerialUIFigure);
app.Label_2.HorizontalAlignment = 'right';
app.Label_2.Position = [13 608 68 28];
app.Label_2.Text = '波特率';
app.Serial_data_bits = uidropdown(app.MySerialUIFigure);
app.Serial_data_bits.Items = {'8', '7', '6', '5'};
app.Serial_data_bits.ValueChangedFcn = createCallbackFcn(app, @Serial_data_bitsValueChanged, true);
app.Serial_data_bits.Position = [100 563 100 25];
app.Serial_data_bits.Value = '8';
app.Label_3 = uilabel(app.MySerialUIFigure);
app.Label_3.HorizontalAlignment = 'right';
app.Label_3.Position = [13 562 68 28];
app.Label_3.Text = '数据位';
app.Serial_stop_bits = uidropdown(app.MySerialUIFigure);
app.Serial_stop_bits.Items = {'1', '1.5', '2'};
app.Serial_stop_bits.ValueChangedFcn = createCallbackFcn(app, @Serial_stop_bitsValueChanged, true);
app.Serial_stop_bits.Position = [100 517 100 25];
app.Serial_stop_bits.Value = '1';
app.Label_4 = uilabel(app.MySerialUIFigure);
app.Label_4.HorizontalAlignment = 'right';
app.Label_4.Position = [13 515 68 28];
app.Label_4.Text = '停止位';
app.Serial_check_bits = uidropdown(app.MySerialUIFigure);
app.Serial_check_bits.Items = {'none', 'even', 'odd'};
app.Serial_check_bits.ValueChangedFcn = createCallbackFcn(app, @Serial_check_bitsValueChanged, true);
app.Serial_check_bits.Position = [100 471 100 25];
app.Serial_check_bits.Value = 'none';
app.Label_5 = uilabel(app.MySerialUIFigure);
app.Label_5.HorizontalAlignment = 'right';
app.Label_5.Position = [13 469 68 28];
app.Label_5.Text = '校验位';
app.Signal_select = uidropdown(app.MySerialUIFigure);
app.Signal_select.Items = {'串口助手', '雷达信号'};
app.Signal_select.ValueChangedFcn = createCallbackFcn(app, @Signal_selectValueChanged, true);
app.Signal_select.Position = [100 425 100 25];
app.Signal_select.Value = '雷达信号';
app.Label_10 = uilabel(app.MySerialUIFigure);
app.Label_10.HorizontalAlignment = 'right';
app.Label_10.Position = [13 424 68 28];
app.Label_10.Text = '接收选择';
app.Serial_Switch = uiswitch(app.MySerialUIFigure, 'slider');
app.Serial_Switch.Items = {'关闭', '开启'};
app.Serial_Switch.ValueChangedFcn = createCallbackFcn(app, @Serial_SwitchValueChanged, true);
app.Serial_Switch.Position = [130 371 56 25];
app.Serial_Switch.Value = '关闭';
app.Serial_Lamp = uilamp(app.MySerialUIFigure);
app.Serial_Lamp.Position = [51 371 25 25];
app.Serial_Lamp.Color = [0.651 0.651 0.651];
app.MySerialUIFigure.Visible = 'on';
end
end
methods (Access = public)
function app = Serial_app
createComponents(app)
registerApp(app, app.MySerialUIFigure)
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
end
end
function delete(app)
delete(app.MySerialUIFigure)
end
end
end