我正在尝试从串行端口读取数据并绘制图形。
我收到读取失败的警告:在超时时间内未返回指定的数据量。
请帮助我克服这个警告
我添加了mu代码作为参考。
我在data(i)= fread(s)时遇到错误
close all;
clc;
clear all;
s = serial('COM5');
ll=0;
s.InputBufferSize = 1;
try
fopen(s);
catch err
fclose(instrfind);
error('Make sure you select the correct COM Port where the Arm is connected.');
end
%while 1
Tmax = 20;
figure,
grid on,
xlabel ('Time (s)'), ylabel('In Amplitude'),
axis([0 Tmax+1 -10 255]),
Ts = 0.002;
i = 0;
data = 0;
t = 0;
tic
while toc <= Tmax
i = i + 1;
data(i) = fread(s)
if data(i)>200
ll=1+ll;
end
t(i) = toc;
if i > 1
T = toc - t(i-1);
while T < Ts
T = toc - t(i-1);
end
end
t(i) = toc;
if i > 1
line([t(i-1) t(i)],[data(i-1) data(i)])
drawnow
end
%data=0;
end
%end
img = screencapture(0, 'Position', [0 0 1270 1023]);
imwrite(img,'output.jpg');
fclose(s);