Serial Port won't clear after halting debugging

I am debugging code using the serial port. If I exit the debug session normally via <shift>F5, I cannot reopen the serial port upon restarting a new debug session. I get the error listed at the bottome of this post. I have to shutdown matlab completely to clear everything.
I can understand why the port is still open (it was not closed upon exiting debug), however I need a way to "clear" it and reopen it after the next debug session.
I issue the 'delete(instrfindall)' at the start of the program but this does not work.
Thanks for any ideas, Fritz
==============================================
??? Error using ==> serial.fopen at 72
Cannot connect to the COM5 port. Possible reasons are another
application is connected to the port or the port does not exist.
Error in ==> spectrometer_monitor at 39
fopen(s);

2 Kommentare

Ariel
Ariel am 27 Aug. 2013
Hello Fritz.
My name is Ariel and I'm dealing the same problem. have you found solution?
Thank you
Ariel
Ivan Peric
Ivan Peric am 23 Jan. 2018
You can try this: -right click myCoumputer -properties -device manager -serial -ports -right click your port -disable -enable

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Adam
Adam am 16 Aug. 2011

0 Stimmen

instrreset
is your friend!
Clear the serial object then issue an instrreset.

4 Kommentare

Adam, I tried it (below) but I still have the same problem.
Fritz
delete(instrfindall)
instrreset;
s = serial('COM5');
set(s,'BaudRate',115200);
set(s,'InputBufferSize',80000); %won't work without this
fopen(s);
Adam
Adam am 16 Aug. 2011
Try:
delete(instrfindall)
clear s;
instrreset;
...rest of the code...
Adam
Adam am 16 Aug. 2011
From MATLAB documentation on delete:
"Remarks
When you delete obj, it becomes an invalid object. Because you cannot connect an invalid serial port object to the device, you should remove it from the workspace with the clear command."
Adam
Adam am 23 Aug. 2011
Did that work?

Melden Sie sich an, um zu kommentieren.

Kategorien

Gefragt:

am 16 Aug. 2011

Kommentiert:

am 23 Jan. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by