cancel
Showing results for 
Search instead for 
Did you mean: 

How to remove error like 'COM port is not available even it is available'.

Mohan1
Associate III

Hi, I am using STM32CubeIDE and written a code of transmission .I am taking data in MATLAB serially .First time when ,i run the program in STM32CubeIDE and get correct data in MATLAB by running the MATLAB serial code

//MATLAB serial code
s=serial('COM5','BaudRate',9600);
fopen(s);
data=fscanf(s);
d23=str2num(data)
x=plot(d23);

,but second time when i run the program which is written in MATLAB to get data from COM port,it shows error like 'COM port is not available '.So now what i am doing is closing the MATLAB window and again opening ,that time program in MATLABworks.Please tell me any suggestion over it.

6 REPLIES 6

Perhaps fclose() the stream?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thanks for your quick response sir,sorry sir i am not getting what are you saying?

Close the resources you open, as you probably can't open them a second time.

s=serial('COM5','BaudRate',9600);

fopen(s); // Open stream

...

fclose(s); // Close when done

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

i used it sir but facing same problem again.

Perhaps a problem more deeply inside MATLIB implementation, discuss with their support team or related forums.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

ok sir,thank you.