I'm trying to open a serial port, but Matlab says it's not available. What can i do?

49 ビュー (過去 30 日間)
Od Di
Od Di 2017 年 4 月 8 日
コメント済み: Madalina Dobre 2021 年 12 月 12 日
Hi everyone, I know a lot of people already asked for this but i cannot find any solution. I've got an Arduino board connected to a serial port (COM5), but when i run fopen(serialobj) it fails saying that "COM5 is not available". I tried to open Arduino IDE and uploading another sketch on that port and it went well; even though I close the IDE matlab still gets the same error. I tried with INSTRFIND and the output was
Index: Type: Status: Name:
1 serial closed Serial-COM2
2 serial closed Serial-COM2
3 serial open Serial-COM5
4 serial closed Serial-COM5
5 serial closed Serial-COM3
6 serial closed Serial-COM5
7 serial closed Serial-COM3
8 serial closed Serial-COM3
9 serial closed Serial-COM3
The error message given by Matlab is this:
'Open failed: Port: COM5 is not available. No ports are available.↵Use INSTRFIND to determine if other instrument objects are connected to the requested device.'
Can someone help me? PS: Baudrate is 4800, the same as the one i set on Arduino.
  1 件のコメント
Enrique Paredes Sánchez
Enrique Paredes Sánchez 2021 年 6 月 5 日
I had the same problem, it was due to another program was using the port. I closed it and then it solved.

サインインしてコメントする。

回答 (5 件)

Nim Pim
Nim Pim 2021 年 5 月 2 日
編集済み: Walter Roberson 2021 年 6 月 5 日
Disconnect and delete all the objects using "instrreset". Then it works.

Saurabh Gupta
Saurabh Gupta 2017 年 4 月 12 日
It looks like you already have the port open. You may want to fclose or delete it before trying to fopen it.
  2 件のコメント
Peter Nelson
Peter Nelson 2019 年 3 月 26 日
Doesn't work for me. I tried inserting the solution provided in the answer from SG:
if ~isempty(instrfind)
fclose(instrfind);
delete(instrfind);
end
but I still get the error. The only fix is to leave and re-start Matlab.... sometimes several times before it allows me to open it with the serial command. In my case its a USB port. Any other ideas???
Madalina Dobre
Madalina Dobre 2021 年 12 月 12 日
hi,did you get a fix for this? i have the same issue

サインインしてコメントする。


Davide Nicolò Fortunato
Davide Nicolò Fortunato 2019 年 4 月 19 日
I have the same problem, but i have an elegoo uno board. (the microcontroller is the same atmega of arduino uno).
i have yet tried
if ~isempty(instrfind)
fclose(instrfind);
delete(instrfind);
end
but nothing :(

Renner Josef
Renner Josef 2019 年 6 月 4 日
Does work for me so far with an elegoo MEGA2560 R3.
Thanks for your help.

alican kara
alican kara 2020 年 6 月 20 日
編集済み: Image Analyst 2020 年 6 月 20 日
MATLAB Serialport connection between Computers

カテゴリ

Help Center および File ExchangeMATLAB Support Package for Arduino Hardware についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by