该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
clear;clc;
global s1;%%//s1为光电测速传感器返回值
global s2;
s1=serial('COM4');
set(s1,'BaudRate',38400);
s1.BytesAvailableFcn=@dianjibiaocan_receiveFcn_3;
s1.BytesAvailableFcnMode='byte';
% s1.BytesAvailableFcnCount=1;
s1.ReadAsyncMode='continuous';
fopen(s1);
s1.status
global loopCount;
global CountTimes;
global BackTime;
global velocity;
global distance;
global a;
global T;
global PeriodTime;
PeriodTime=0.015;
%%----------------主函数(执行循环)使程序不断运行--------------
loopCount=1;
BackTime=[];
CountTimes=[];
velocity=[];
distance=[];
T=0;
disp('started\n');
power=240;
while 1
tstart=tic;
tused=0;
switch loopCount
case 50
disp('The sensor has send datas back for 50times')
disp(a(loopCount-1))
disp(velocity(loopCount-1))
case 100
disp('The sensor has send datas back for 100 times ')
disp(a(loopCount-1))
disp(velocity(loopCount-1))
break
otherwise
end
% /*********空执行定时延时程序*********/
while (tused
tused=toc(tstart);
end
end
b=0;
fprintf(s1,'%d\n',b);
fclose(s1);
delete(s1);
clear s1;