Info

此问题已关闭。 请重新打开它进行编辑或回答。

SimEvent Resource local to a subsystem

1 次查看(过去 30 天)
Caroline Brandberg
Caroline Brandberg 2018-1-25
关闭: MATLAB Answer Bot 2021-8-20
Hi,
I would like to create a reusable subsystem which contains a SimEvent Resource which it acquires and releases locally to that subsystem.
If I copy and paste such subsystem, I will get an error telling me that I have two resources with the same name.
I tried to create a mask for the subsystem, and thereafter create an attribute to be used to separate the different resources. But, I couldn't acquire a resource identified by a name specified in the mask for the subsystem...
All suggestions are appreciated!
Thanks

回答(1 个)

Gaurav Phatnani
Gaurav Phatnani 2018-2-2
You can implement the desired behavior in the 'CopyFcn' callback (Right click> Properties> Callbacks) of the original subsystem. Here, you will need a script which checks the number of existing Resource Pools in your model and then generates a new name and assigns it to the 'Resource Pool' inside the newly created subsystem. For ex, if 3 'Resource Pool' blocks exist, the new name will be 'Name4'.
The script inside the 'CopyFcn' callback should look like this: 1. Use 'find_system' to return a list of all existing 'Resource Pool' blocks.
>> l = find_system(gcs,'SearchDepth',2,'LookUnderMasks','all','BlockType','EntityResourcePool');
2. The length of the list represents the number of 'Resource Pool' blocks in your system. If the 'Resource Name' is 'Name' for the original block, the subsequent copies will have resource names 'Name1', 'Name2', 'Name3' etc. Use 'set_param' to set the desired name
>> set_param([gcb '/Resource Pool'], 'ResourceName',['Name' num2str(length(l))]);
Set the above callback in the original subsystem and delete any pre-existing copies. Now if you make copies from the original subsystem you will find that the 'Resource Names' are 'Name2',' Name3', 'Name4' etc. Making a copy from a copy will also produce a unique name.

产品

Community Treasure Hunt

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

Start Hunting!

Translated by