problem of using serial port
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Walter Roberson
le 14 Août 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
le 16 Août 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.
Réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!