instrfindall function finds only legacy serial and instrument objects (serial, visa, tcpip, etc.), and it will not work with the new serialport interface.
While currently there is no equivalent function that has the same functionality as the legacy instrfind or instrfindall, the following approaches can be used to disconnect from hardware when using the new serialport interface. Note that the example is for serialport, however the same approach should work for tcpclient, tcpserver, udpport, visadev, bluetooth.
Disconnect from a COM port when using serialport object
- If the serialport object s exists in the base MATLAB workspace, as created from the command line or script, you can call the clear function
s = serialport("COM1",9600);
...
% communication operations
...
% Disconnect and clear the object
clear(s)
- If the serialport object handle is stored in a property of another object, for example an app created with App Designer, you can call the delete function to disconnect from the COM port:
% serialport object is created in app code
s = serialport("COM1",9600);
app.Connection = s;
...
...
% To disconnect, you can call delete in app code, for example from a button callback function
delete(app.Connection)
