Why am I unable to use my serial port after a hardware reset if the port was open in MATLAB?

18 views (last 30 days)
I use USB-devices that create virtual serial ports in Windows, for instance COM5. When MATLAB opens a connection with one of these devices and the device disconnects and reconnects, I am unable to use the device any more. What can I do to regain access to the device?
 
myComPort = serial('COM5');
fopen(myComPort);
% now disconnect the device
% now connect the device again, the following will be unsuccessful:
delete(myComPort)
clear myComPort
myComPort = serial('COM5');
fopen(myComPort);
Error using serial/fopen (line 72)
Open failed: Port: COM5 is not available. Available ports: COM1, COM3.
Use INSTRFIND to determine if other instrument objects are connected to the requested device.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 21 May 2015
When a serial port connection is opened and the device becomes unavailable, the device remains unavailable after reconnecting. There is currently no way in MATLAB to fully reset the status of this connection, once this state is reached.
As a workaround you can first delete the serial port connection and then reconnect the device. For instance:
 
myComPort = serial('COM5');
fopen(myComPort);
% now disconnect the device
delete(myComPort)
clear myComPort
% now connect the device again, the following will now be successful:
myComPort = serial('COM5');
fopen(myComPort);
  1 Comment
Rutuja Shirali
Rutuja Shirali on 7 Jul 2015
Hello Chrono. Please contact MathWorks Technical Support and create a ticket about this issue. Some engineer from the team will investigate further.

Sign in to comment.

More Answers (0)

Categories

Find more on Data Acquisition Toolbox Supported Hardware in Help Center and File Exchange

Products


Release

R2013b

Community Treasure Hunt

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

Start Hunting!