I am trying to read data from serial port. The port being used is COM1. I am getting the following error :
??? Error using ==> serial.fopen at 72
Port: COM1 is not available. Available ports: COM8, COM17, COM19.
Use INSTRFIND to determine if other instrument objects are connected to the requested device.
Please suggest possible reasons.
[Merged information from duplicate question]
I am using Windows 7 32 bit. Matlab verison is 2011a.

7 Comments

Duplicate question has been deleted for everyone's convenience.
Geoff
Geoff on 30 May 2012
Do you mean possible reasons OTHER than what the error message suggests? Have you looked at your Device Manager to confirm whether COM1 exists on your system? Did you open the port successfully before? Did you use fclose() to close it before trying to open it again? Are you running any other software that might be using that port?
skyimager
skyimager on 31 May 2012
No sir. I meant reasons of this error. Yes when i first start my matlab it works fine. But after 2-3 tries it stops and starts displaying error.
The port is available and free.
Does anyone have a REAL answer to this? I get this message when I have a code error and I have to completely close out of Matlab. Delete(instrfind) used to solve this but it no longer works in 2015a for me.
My May 30 2012 response is a whole series of REAL answers.
There are additional REAL answers, many of them. You do not even happen to mention which device you are using or which operating system.
The REAL answer in the case you are encountering might be that the manufacturer of the device might refused to take seriously a report from a QA (Quality Assurance) person that under a particular set of circumstances the driver could potentially get wedged. (I know a hardware QA person whose reports are routinely dismissed by their manager; the QA person has been with the product line for years longer than any of the current managers or developers, and the QA person gets outright accused of making things up because the QA person knows how the device does work, not just how the device is intended to work.)
The underlying cause might have been failing to work around a bug in MS Windows when such-and-such a hotfix is installed in some specific Service Pack version of a particular edition of MS Windows. Getting Microsoft to admit the problem might have been a multi-year chore in itself. The code might be "right"... compared to what the interface is documented to do, which could be quite different than what the interface does do under edge conditions.
Is this what is happening in your particular situation? We don't know. There isn't only one reason why things happen.
Thisara
Thisara on 13 Aug 2016
Edited: Thisara on 13 Aug 2016
use this code on first line of script
delete(instrfindall);
@ Thisara Thanx it worked

Sign in to comment.

 Accepted Answer

Walter Roberson
Walter Roberson on 30 May 2012

0 votes

1) The COM port name you are trying to use perhaps does not correspond to a valid COM port
2) The COM port might already be in use in that MATLAB session. Quit and restart MATLAB and try again.
3) COM1 might already be allocated for the mouse (serial mouse, older systems)
4) COM1 might already be allocated for use as a modem (a problem seen more often on laptops)
5) You are using a virtual COM port over USB and you did not have it connected at the time you started MATLAB
6) You are using a virtual COM port over USB and you disconnected it at least once after you started MATLAB
7) You are using an older system in which COM1 shares the interrupt line with COM5 and COM5 is already in use
8) Installation problems
9) User Access Controls set up on COM1 do not allow you to use it
10) It is MS Windows; it doesn't need any good reason to act oddly.

2 Comments

skyimager
skyimager on 31 May 2012
I checked in my device manager. COM1 is the port that the arduino is connected to. Also using instrfind command i confirmed that COM1 is available.
I read somewhere that we have to define the ports we propose to use in our program in the matlab library. But I don't know how to define that.
I _suspect_ that you might be referring to defining the port when using Linux, as Linux's serial port names are a lot more complex than "COM1".
Anyhow, if you had the program crash (easy enough to have happen during development) then the serial port might not have gotten closed properly. Try fclose('all')

Sign in to comment.

More Answers (1)

Thisara
Thisara on 13 Aug 2016

1 vote

use this code on first line of script
delete(instrfindall);

Community Treasure Hunt

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

Start Hunting!