serialport - how to reopen port after handle was lost

10 visualizzazioni (ultimi 30 giorni)
Lukas Mayer
Lukas Mayer il 14 Dic 2021
Risposto: kate_w il 26 Apr 2023
During replacing serial with serialport, I cannot open the port again after the handle was lost (e.g. because it was used in a function that terminated with an error).
I seem to be able to reset the port and reopen with serialport by using clear all but that cannot be it!? Isn't there something that works like delete(instrfind) for the older serial function?
In other words: what would i need between line 2 and line 3 if I lost the variable s:
clear all;
s=serialport('COM9',115200);
t=serialport('COM9',115200);
Error using serialport (line 116)
Unable to connect to the serialport device at port 'COM9'. Verify that a device is connected to the port, the port is not in use, and all serialport input arguments and parameter
values are supported by the device.
See related documentation for troubleshooting steps.
Please help!

Risposte (1)

kate_w
kate_w il 26 Apr 2023
I found something that might help:
delete(instrfind({'Port'},{'COM9'}));

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by