I understand that you’re encountering issues with re-establishing the serial connection after an error in communication. Here are a few suggestions you can try to resolve the problem:
- Serial Communication update: Following the MATLAB R2019b release, the serial communication has been updated, there has been no equivalent function that has the same functionality as the legacy “instrfind” or “instrfindall”. To find alternate approaches you may refer: https://www.mathworks.com/matlabcentral/answers/886269-how-do-i-close-serialport-objects
- Check for Zombie Processes: Sometimes, even after the serial object is closed and cleared, MATLAB might still maintain a reference to the port, preventing it from reconnecting. This can happen if the serial object is not properly deleted and cleared. Make sure you don't have any zombie serial port objects.
- Check for COM Port Availability: Ensure that the COM port you're trying to reconnect to is not being used by another process or program. If it's still locked, then it might not be able to establish a new connection.
- Physical Cable Connection: Ensure that the physical cable connection itself is stable and not causing intermittent disconnects.
Hope these suggestions will help resolve the issue. If it persists, it might be helpful to check the documentation for your hardware devices and check if there are any specific recommendations for handling reconnections.