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 CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by