Resource acquire block programmatic use

1 回表示 (過去 30 日間)
Marco Fanti
Marco Fanti 2019 年 4 月 1 日
回答済み: Krishna Akella 2019 年 4 月 4 日
Hello,
I'm building a SimEvents model programmaticaly and I have the following problems regarding the "Resource Acquire", "Resource Release" and "Resource Pool" blocks:
  1. I am not able to find the using the "add_block" command. An error comes out saying there is no such a block in the library.
  2. I partially solved the problem by manually creating the blocks in a different model and then programmaticaly pasting them on a new model. The problem is still that I would like to be able to change block paramters directly from code. The parameters that i would like to change are:
  • For Resource Acquire block: resource to be acquired and amount.
  • For Resource Release block: resource to be released
  • For Resource Pool block: resource name and relative amount.
Thanks.

採用された回答

Krishna Akella
Krishna Akella 2019 年 4 月 4 日
Hi Marco,
To know the BlockType of any block, add the block to a model and select it. Then in MATLAB window, type the following:
>> h = get_param(gcb, 'Handle');
>> get(h, 'BlockType')
ans =
'EntityResourceAcquirer'
>>
To add a EntityResourceAcquirer to a model, you can type:
>> add_block('built-in/EntityResourceAcquirer', [gcs '/R1'], 'MakeNameUnique', 'on')
Similarly to know the block parameters for a block, you can select the block in the model and use:
>> get_param(gcb, 'DialogParameters')
ans =
struct with fields:
ResourceName: [1×1 struct]
ResourceAmountSource: [1×1 struct]
ResourceAmount: [1×1 struct]
...
Then use the following to set the block's values:
>> set_param(gcb, 'ResourceName', 'Resource1', 'ResourceAmountSource', 'Dialog', 'ResourceAmount', '1')
Hope that helps!
Regards,
Krishna

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by