Update App GUI with Simulink data in real-time

6 ビュー (過去 30 日間)
Byron Piper
Byron Piper 2022 年 7 月 18 日
コメント済み: Jon 2022 年 7 月 18 日
Essentially I have a value within a MATLAB function which is updated each interval of my Simulink model. I would like to access this value in my app and use it to update the interface in real-time. For this I believe I need some sort of callback to allow the model to call a function in my app so that I can simply grab this data. How would I do this?
The only way I've been able to make this work is create a new instance of my app and attach a listener to that, which obviously means it opens a new window which is not what I want. I want to attach the listener to the window that's currently open.

回答 (1 件)

Jon
Jon 2022 年 7 月 18 日
Please provide a little more context. From what you describe it sounds like your Simulink model has an interpreted MATLAB function block ("I have a value within a MATLAB function which is updated each interval of my Simulink model") is that correct? Otherwise exactly what kind of value in your Simulink model do you want to get?
If you just want a block parameter value that may change, you can use get_param to get the value. If you want data from an InputPort or OutputPort you will need to access the block's Run-TimeObject https://www.mathworks.com/help/simulink/ug/accessing-block-data-during-simulation.html
In any case, what I have done regarding communicating between Simulink and my App Designer Gui for soft real time application is (omitting many details) the following:
  1. To provide some decoupling between my app and the simulink model I make an interface object that can get data in an out of the simulink model. In this interface object I have an event that the gui can listen for that lets it know when new data is available.
  2. I use a MATLAB timer, and corresponding timer callback that periodically gets the desired value from the Simulink model (e.g. using the Run-Time object). This timer callback function saves the data as a property of my interface object and notifies event listeners (in particular the gui app) that a value has been changed.
  3. My app listens for this event, and when it occurs it gets the data from the interface object (it is just a property of the interface object) and it writes the data to the appropriate data fields (edit fields, tables etc) in my gui.
  1 件のコメント
Jon
Jon 2022 年 7 月 18 日
If you don't care about decoupling your Gui from your model, you could probably streamline this further. I like having them somewhat decoupled though, so that if I change my model I don't break my Gui and vice versa

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

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by