My computer is connected to a LED light source over a virtual com port. The LED light source crashes from time to time. If this is the case, I have to restart it, which I can do over this com port (the crash is a power failure. The light source is not working properly anymore, but I still can communicate with it). The problem is, that after the restart, I'm not anymore able to connect to it. I'm trying to establish a new connection with
connection = serial('COM14','BaudRate',9600);
fopen(connection)
If I execute the fopen command, I get the following error message:
Error using serial/fopen (line 72)
Open failed: Port: COM14 is not available. Available ports: COM12,
COM14, COM15.
Use INSTRFIND to determine if other instrument objects are connected to
the requested device.
If I restart Matlab, I am able to reconnect. Do you know if there is any workaround?

댓글 수: 14

Adrian Dronca
Adrian Dronca 2013년 3월 5일
편집: Adrian Dronca 2013년 3월 5일
If you are able to reconnect after restart my guess is that Matlab opens the connection and keeps it open, or keeps it in the memory.
Then you cannot connect anymore because it is already in use.
Do you also close it ?
Edit: one hint is that you have an error in your code. Do you always check for errors ?
Stiphu
Stiphu 2013년 3월 6일
Yes, I do close the com port. And there is no error in the code, or do you see one in this two lines of code? The strange thing is that it says that Port 14 is not available and then says that Port 14 is available.
Benjamin
Benjamin 2013년 5월 30일
편집: Benjamin 2013년 5월 30일
I'm experiencing the same problem and would be very interested in a solution (port unavailable, yet available). The port is closed and deleted, yet I get the following message:
fopen(serial('COM3'))
Open failed: Port: COM3 is not available. Available ports:
COM3, COM5, COM6, COM7, COM8.
It can be solved by restarting the system. Until it fails again after some hours of com port use.
Bergercookie
Bergercookie 2015년 9월 16일
편집: Bergercookie 2015년 9월 16일
I had the same problem. There is a similar post ( http://www.mathworks.com/matlabcentral/newsreader/view_thread/145681 ) in which a working solution is presented.
Essentially you can resolve the problem by issuing the following command
delete(instrfindall);
delete(instrfindall);
This statement has solved my issue, thank you so much for you help.
abhinay kumar
abhinay kumar 2017년 12월 7일
This also solved my problem. Thank You.
a m
a m 2018년 5월 30일
This also solved my problem. Thank You.
ehsan ghaderi
ehsan ghaderi 2018년 6월 20일
This also solved my problem. very very Thank You .
Amirabbas Amrollahi
Amirabbas Amrollahi 2019년 6월 26일
where sould i add this suggested comand?
Mahmoud Abulwafa
Mahmoud Abulwafa 2019년 10월 7일
at the end i guess
Walter Roberson
Walter Roberson 2019년 10월 7일
It would go at the beginning. It would clean up after whatever had gone before.
You should also make sure to release the port when you are done with it.
Ashirwad Gad
Ashirwad Gad 2019년 11월 15일
@Walter Roberson, thanks for that tip on releasing the port. Now how is it done exactly or is it the same as delete(instrfindall) ?
Walter Roberson
Walter Roberson 2019년 11월 15일
delete() the serial port object when you are through with it. Consider using an onCleanup() in case of a code crash
Ashirwad Gad
Ashirwad Gad 2019년 11월 15일
alright thanks!

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

답변 (1개)

Nhat Nguyen Thanh Minh
Nhat Nguyen Thanh Minh 2018년 5월 21일

0 개 추천

thanks for your help !

카테고리

도움말 센터File Exchange에서 COM Component Integration에 대해 자세히 알아보기

제품

질문:

2013년 3월 5일

댓글:

2019년 11월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by