serial port communication

조회 수: 1 (최근 30일)
Max
Max 2011년 10월 16일
hi
my objective is to obtain the 8 bit data via a serial port and also receive 8 bit data via the serial port ...
following basics codes i am using now
s = serial('COM1'); fopen(s) fprintf(s, '8') idn = fscanf(s); fclose(s)
following errors are coming
Port: COM1 is not available. No ports are available. Use INSTRFIND to determine if other instrument objects are connected to the requested device.
Error in ==> jk at 3 fopen(s)
i need to know the problem and a solution in the form of alternative codes ...
thank you

답변 (1개)

Walter Roberson
Walter Roberson 2011년 10월 16일
The serial port is not available. Perhaps it is already open for some other purpose. Perhaps you opened the port in an earlier run during the same session and you did not close it again (because the program crashed, perhaps) ?
It would be a good idea to follow the suggestion from the error message and use instrfind to determine if the port is already open. See the last example in the reference documentation for instrfind
  댓글 수: 1
Max
Max 2011년 10월 20일
thanks walter

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

Community Treasure Hunt

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

Start Hunting!

Translated by