The specified amount of data was not returned within the Timeout period or A timeout occurred before the Terminator was reached

5 visualizzazioni (ultimi 30 giorni)
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 Commento
Akina
Akina il 7 Apr 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

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 2 Dic 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?
  1 Commento
Jin
Jin il 2 Dic 2013
I am not sure if this answers that, but when I display the Read/Write State, it says ValuesSent: 3 and Values Received:0 when their is an error. I am not sure if this is referring to the device or Matlab. It does work sometimes which I think means it does indeed receive the command, but I don't know how to check whether the device reads the command properly or sends something back.
Thank you for your response. The following is the status of the serial port when it gives an error: Serial Port Object : Serial-COM3
Communication Settings
Port: COM3
BaudRate: 9600
Terminator: 'CR'
Communication State
Status: open
RecordStatus: off
Read/Write State
TransferStatus: idle
BytesAvailable: 0
ValuesReceived: 0
ValuesSent: 3

Accedi per commentare.

Categorie

Scopri di più su Performance and Memory in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by