COM port is not reconnecting

10 visualizzazioni (ultimi 30 giorni)
Igor Nakonechnyi
Igor Nakonechnyi il 9 Ago 2022
Risposto: Dhruv il 31 Ago 2023
Hi community,
I have a problem with communicating with external harware using MATLAB. I have a script for measurements that is connected to a bunch of hardware, including Arduino, MODBUS, Visa and serial. So far I don't have issues only with hardware connected via visa.
The problem is that once some error in serial communication occurs it's not really possible to reconnect to the hardware without physically unplugging the cable. I am trying to set the serial object to [], I am using delete(instrfindall), instrreset, but it doens't really help.
Any tips and tricks on how to reset the serial connection?
regards, Igor.

Risposte (1)

Dhruv
Dhruv il 31 Ago 2023
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.

Categorie

Scopri di più su Use COM Objects in MATLAB in Help Center e File Exchange

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by