2
votes

I am trying to read data from the serial port of my laptop. The data is coming from the MSP430 through COM13.

When I try to access the data through MATLAB, it says -

??? Error using ==> serial.fopen at 72 Port: COM13 is not available. No ports are available. Use INSTRFIND to determine if other instrument objects are connected to the requested device.

Error in ==> interfaceplot at 3 fopen(s)

The code I am using is this-

s = serial('COM13'); %assigns the object s to serial port

set(s, 'InputBufferSize', 128); %number of bytes in inout buffer
set(s, 'FlowControl', 'none');
set(s, 'BaudRate', 9600);
set(s, 'Parity', 'none');
set(s, 'DataBits', 8);
set(s, 'StopBit', 1);
set(s, 'Timeout',100);
%clc;

disp(get(s,'Name'));
prop(1)=(get(s,'BaudRate'));
prop(2)=(get(s,'DataBits'));
prop(3)=(get(s, 'StopBit'));
prop(4)=(get(s, 'InputBufferSize'));

disp([num2str(prop)]);

fopen(s);           %opens the serial port

data = fscanf(s);

fclose(s); %close the serial port
1
What is the output of INSTRFIND?Daniel
Instrument Object Array Index: Type: Status: Name: 1 serial closed Serial-COM13 2 serial closed Serial-COM13 3 serial closed Serial-COM13Swathi Sham

1 Answers

3
votes

Usually as pointed out by matlab and the Commenter, instrfind looks for objects to use your serial ports. A radical way to close all of those (unwanted) connections is:

fclose(instrfindall);
delete(instrfindall);

This closes all connections and deletes the objects. Typing instrfind shows you [] afterwards. If this doesn't work try to reconnect the device or restart the computer and then try again. Last thing I can think of is using the terminal/command line whatever (I'm on UNIX) and google how to find out what process uses which COM port. Then terminate the process and try again.

Not needing to say, that you need to close all other programs using that COM port. Be sure of that (it's easily forgotten).