No BSD License  

4.6 | 7 ratings Rate this file 49 Downloads (last 30 days) File Size: 1.05 KB File ID: #9251

Get Available COM PORT


Daniel Lavoie (view profile)


05 Dec 2005 (Updated )

Get available COM port on your PC

| Watch this File

File Information

This function output a cell array with string name of each COM port available on your PC.

 COM_Port = getAvailableComPort();


MATLAB release MATLAB 7.0.1 (R14SP1)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (7)
16 Jan 2015 Josiah Renfree

Did exactly what I was looking for. However, I ended up modifying the code quite a bit, as parsing the error string for the COM ports can more easily be done using regexp.

13 Jan 2015 Vlad

Vlad (view profile)

Good job! Was looking for a function like this for some time :-) Thanks

07 Jan 2015 James D.B. Wang

Good job, man. It really helps in real-time case.

18 Nov 2012 Nikolay S.

Nikolay S. (view profile)

Excellent- works like magic, thanks!

10 May 2009 Geoffrey Akien

Very handy utility, but unfortunately the way MATLAB finds these serial ports does not take into account if other programs are using them - although fopen will of course prevent you from using that port. Also, when I incorporated it into a GUI, it did not stand up to being run a second time - it could not access the error message which instead replies with a 0x1 structure.

23 Jan 2009 Marko Antila

Nice work Daniel - clever to catch the error message. I was thinking this myself but did not have time to work it out.

I think, however that the code could be further improved by inserting these two lines after the first "end":

This removes the unnecessary handle and does not confuse the future operations with the serial port.

04 Jan 2006 anders granstroem

Shows available COM ports. When terminating a matlab program with CTRL-C. Windows 2000 thinks that the com port is occupied. Nice to se this in matlab. Can be seen by doing "mode" command at the command promt in windows as well.

Contact us