The specified amount of data was not returned within the Timeout period or A timeout occurred before the Terminator was reached
5 次查看(过去 30 天)
显示 更早的评论
Hello Matlab community,
I am having a problem with Matlab and I'm hoping someone can help me. I am trying to use serial port communication to read data from my device, but when I try it gives me back either no data with the error above or the correct data. Using fscanf will give me the "A timeout occurred before the Terminator was reached" error while using fread will give me the "The specified amount of data was not returned within the Timeout period" error. The device will give me back information possibly three out of every ten reads. I am a complete novice when it comes to Matlab so I would really appreciate help. The following is my code:
s = instrfind('Port','COM3');
if isempty(s)
s = serial('COM3','BaudRate',9600,'ByteOrder','littleEndian','DataBits',8,'Parity','none','StopBits',1,'Terminator','CR','Timeout', 1);
else
fclose(s);
delete(s);
s = s(1)
end;
fopen(s);
for i = 1:10
fprintf(s,'IR');
bytesava = s.BytesAvailable
T = fread(s)
pause(0.2)
end
end
fclose (s)
delete (s)
clear all
Best Regards,
Jin
1 个评论
Akina
2015-4-7
Hi,
I know this thread is an old one, but I'm wondering if you had found solution to the problem you had. I'm having difficulty getting my device (hand-dynamometer) reads input via USB (CP2102) and getting exactly what you've gotten. It'd be great if you had any suggestion on this!
Best,
Akina
回答(1 个)
Walter Roberson
2013-12-2
Your line
T = fread(s)
requests that data be read until BufferSize bytes of data have been read, or a terminator has been seen.
Have you been able to confirm on the receiving side that the IR\r being sent to the device is being received and replied to?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Performance and Memory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!