problem of using serial port

3 views (last 30 days)
Fan Sudi
Fan Sudi on 14 Aug 2012
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 Comments
Walter Roberson
Walter Roberson on 14 Aug 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
Walter Roberson on 16 Aug 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.

Sign in to comment.

Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!