The specified amount of data was not returned within the Timeout period or A timeout occurred before the Terminator was reached
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Akina
el 7 de Abr. de 2015
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
Respuestas (1)
Walter Roberson
el 2 de Dic. de 2013
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?
Ver también
Categorías
Más información sobre Performance and Memory en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!