Skip to main content
Mohan1
Associate III
November 5, 2019
Question

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

  • November 5, 2019
  • 1 reply
  • 1113 views

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.

This topic has been closed for replies.

1 reply

Tesla DeLorean
Guru
November 5, 2019

Perhaps fclose() the stream?

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Mohan1
Mohan1Author
Associate III
November 5, 2019

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

Tesla DeLorean
Guru
November 5, 2019

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 VenmoUp vote any posts that you find helpful, it shows what's working..