How to clear Arduino connection when it is a member of handles in GUI?

10 ビュー (過去 30 日間)
Zicong Zhang
Zicong Zhang 2020 年 12 月 15 日
コメント済み: Zicong Zhang 2020 年 12 月 23 日
I recently started building a GUI to set up a small control system based on arduino. Here is the thing. I set up my arduino in the opening function with following code
handles.board=arduino();
I thought this would be helpful since I only need to pass the handles variable. It worked pretty well. But after I close the GUI, it cant not start again due to the error below.
MATLAB connection to Due at COM4 exists in your workspace. To create a new connection, clear the existing object
I might need to clear the arduino variable just as MATLAB arduino tutorial does. But after i close the GUI, running 'clear' or 'clear all' cannot solve the problem. Meanwhile, if I restart the GUI with the arduino line being commented, there won't be a board member in handles. So the handles is destroyed after GUI is shut down but the connection is still there. What should I do?

採用された回答

Kiran Felix Robert
Kiran Felix Robert 2020 年 12 月 18 日
編集済み: Kiran Felix Robert 2020 年 12 月 18 日
Hi Zicong,
Try clearing out the Arduino object in the CloseRequestFcn. This callback executes whenever you try to close your GUI, so you might be able to clear the connection.
Also use the following function to clear the board object.
clear aurduino_object ;
  1 件のコメント
Zicong Zhang
Zicong Zhang 2020 年 12 月 23 日
Thank you for your help! That works perfectly!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Support Package for Arduino Hardware についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by