Serial Communication Timeout Warning
13 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have been using the following code to simply send data through a usb to an oscilloscope and although I have been able to send data just fine, I am receiving the the following timeout warning. Can someone help me figure out why this is showing up and how to fix it?
Code:
clc;
clear;
string1=[200,200,200,200,200]
obj1 = instrfind('Type', 'serial', 'Port', 'COM5', 'Tag', '');
set(obj1, 'timeout',.5);
if isempty(obj1)
obj1 = serial('COM5');
else
fclose(obj1);
obj1 = obj1(1)
end
fopen(obj1);
fwrite(obj1,string1,'uint8')
A=fread(obj1)
fclose(obj1);
Warning:
Warning: Unsuccessful read: The specified amount of data was not returned
within the Timeout period.
1 commentaire
Daniel Rausch
le 22 Fév 2016
I assume you want to read the Bytes available in the Buffer. Try A=fread(obj1,get(obj1,'BytesAvailable'))
Réponses (1)
Walter Roberson
le 15 Juin 2015
"A = fread(obj) and A = fread(obj,size) read binary data from the device connected to the serial port object, obj, and returns the data to A. The maximum number of values to read is specified by size. If size is not specified, the maximum number of values to read is determined by the object's InputBufferSize property."
"Rules for Completing a Binary Read Operation
A read operation with fread blocks access to the MATLAB® command line until:
The specified number of values are read.
The time specified by the Timeout property passes.
Note The Terminator property is not used for binary read operations."
You did not specify a size in your fread() code, so it is going to try to read an entire InputBufferSize worth of bytes, ending only if it gets that many or if the timeout occurs. If your sending system is not filling the buffer then you are going to get a timeout.
I would suggest that you specify the count specifically.
1 commentaire
Abhijit Deka
le 24 Avr 2017
Modifié(e) : Abhijit Deka
le 24 Avr 2017
thanks, after this, the slow reception of data was solved too. Communication is now fast as I wanted. and no warning regarding unsuccessful read.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!