serialport - how to reopen port after handle was lost

9 次查看(过去 30 天)
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!

回答(1 个)

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

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by