MATLAB Answers

SimEvent Resource local to a subsystem

1 view (last 30 days)
Caroline Brandberg
Caroline Brandberg on 25 Jan 2018
Answered: Gaurav Phatnani on 2 Feb 2018
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

  0 Comments

Sign in to comment.

Answers (1)

Gaurav Phatnani
Gaurav Phatnani on 2 Feb 2018
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.

  0 Comments

Sign in to comment.

Sign in to answer this question.