problem of using serial port
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello everyone,
I get a trouble with the Instrument control Toolbox.The USB Driver has alreadly installed.
my code:
s1 = serial('COM3');
serialinfo = instrhwinfo('serial') ;
cur = instrfind;
set(s1,'BaudRate',9600) ;
set(s1,'Terminator','CR') ;
fopen(s1) ;
fprintf(s1,'*IDN?') ;
a = fread( s1,10, 'uchar') ;
fclose(s1) ;
delete(s1) ;
clear s1 ;
Warning: Unsuccessful read: The specified amount of data was not returned within
the Timeout period.
a =
Empty matrix: 1-by-0
But when the NDI software was closed,the code can connect only one time to the NDI and get a little data with it's length is 10. When I try again, I will get a warn above.
what can I do?
2 comentarios
Walter Roberson
el 14 de Ag. de 2012
One thing to keep in mind is that fread() is to read an exact number of bytes (or all bytes until end of file), and is not intended to read "a line" which is what you are probably looking for.
I don't think this will fix your difficulty in this situation, but switching to fgetl() would help once you get past the timeout problem.
Walter Roberson
el 16 de Ag. de 2012
Fan Sudi wrote,
I have tried,but get a empty matrix. Warning: Unexpected Warning: A timeout occurred before the Terminator was reached. a = '' but the first loop get a string "RESETBE6F",the others empty.
Respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing 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!