problem of using serial port

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

Walter Roberson
Walter Roberson 2012년 8월 14일
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.
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2012년 8월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by