フィルターのクリア

Set Simulink block values from GUI in a running model using a RunTimeBlock?

1 回表示 (過去 30 日間)
Bjoern
Bjoern 2012 年 6 月 5 日
コメント済み: Arole 2016 年 8 月 1 日
I currently use a RunTimeBlock to read out signal values from my running model to a GUI, something like this.
Now I want to do the opposite and set signal values from GUI using the RunTimeObject. It doesn't seem possible or have I missed something? I "basically" want to do:
  • RunTimeHandle = get_param('MyModel/MyBlock','RuntimeObject')
  • RunTimeHandle.OutputPort(1).Data = 5;
Let me know if you have a good solution or any other thoughts, Thanks! //Bjoern
  1 件のコメント
Bjoern
Bjoern 2012 年 6 月 5 日
I should add: trying to do this I get a error message:
??? Property 'Data' can only be set for an MATLAB S-function block.

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

採用された回答

Kaustubha Govind
Kaustubha Govind 2012 年 6 月 5 日
As the error suggests, the RunTimeHandle.OutputPort(1).Data (or the Data property of any port) is read-only, so you cannot set it from the GUI. The only way to set port data is if you are writing an S-function block and computing the output signal.
I think we may be able to suggest a different solution depending on what your application is. If you simply want to override a signal with a constant value, then you may want to consider adding 2 Constant blocks and a Switch block to your model.
---------
Signal to override ------|> |
| Switch |---------> to other blocks
Constant1 -------|-| >=1 |
| |
Constant2 ---------|> |
---------
Initially, your Switch will have the "Signal to override" selected (Constant1=1). In your GUI callback, set the value of the Constant block using:
set_param('modelname/Constant2', 'Value', '5');
set_param('modelname/Constant1', 'Value', '0');
set_param('modelname', 'SimulationCommand', 'update')
The second line makes it so the value of Constant2 is selected as the output of the Switch. The third line forces Simulink to take note of the new parameter values.
  3 件のコメント
Kaustubha Govind
Kaustubha Govind 2012 年 6 月 13 日
Bjoern: Sorry, I just got a chance to check back on this discussion. From your new post, it looks like you've already found a solution then?
Also, could you please accept my answer if it resolved the question on this posting? Thanks!
Arole
Arole 2016 年 8 月 1 日
Hi, How would I be able to change the constant2 value from fixed to a dynamic one, ie instead of using 5 as hard coded value, it should accept the user input value from GUI

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSimulink Functions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by