COM port is not reconnecting

9 次查看(过去 30 天)
Igor Nakonechnyi
Igor Nakonechnyi 2022-8-9
回答: Dhruv 2023-8-31
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.

回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 Use COM Objects in MATLAB 的更多信息

标签

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by