Make Serial Communication run in differnt thread from Matlab GUI

11 ビュー (過去 30 日間)
Leo Moritz
Leo Moritz 2025 年 11 月 25 日 10:11
コメント済み: Walter Roberson 2025 年 11 月 25 日 20:36
I want to read serial data continuously and display it in multiple plots with high refresh rate and as little delay as possible. Right now, I use a timer to read the serial data but that makes the GUI very sluggish and unresponsive, especially with high refresh rates. I've read that it's not possible to use serial communication in parallel with the GUI but I know that in Java Swing for example, there is something called a "backgroundWorker" and I assume it should be possible to do something like this in a Matlab GUI as well.

回答 (1 件)

Walter Roberson
Walter Roberson 2025 年 11 月 25 日 10:25
When callbacks are enabled, serial port data is collected through some unspecified asynchronous operation.
I believe that the Execution Engine checks whether a callback has been triggered, at the beginning of every line of MATLAB code. (So if you have a tight loop that is coded all on one line, potentially the loop will not get interrupted.)
I believe that serial port callbacks (and timer callbacks) do not need to wait for waitfor() or pause() or drawnow() or figure()
  2 件のコメント
Leo Moritz
Leo Moritz 2025 年 11 月 25 日 17:20
編集済み: Leo Moritz 2025 年 11 月 25 日 17:21
Should i then update the GUI in the serial callback or should i use a seperate timer callback to update at a fixed rate?
Walter Roberson
Walter Roberson 2025 年 11 月 25 日 20:36
Update the GUI in the serial callback.

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

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

製品


リリース

R2025b

Community Treasure Hunt

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

Start Hunting!

Translated by