Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

SimEvent Resource local to a subsystem

2 vues (au cours des 30 derniers jours)
Caroline Brandberg
Caroline Brandberg le 25 Jan 2018
Clôturé : MATLAB Answer Bot le 20 Août 2021
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

Réponses (1)

Gaurav Phatnani
Gaurav Phatnani le 2 Fév 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.

Cette question est clôturée.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by