- Load all the necessary models in the library.
- Search for an exhaustive list of block types such as “BusCreator”, “BusSelector”, “Inport”, “Outport”, ”Subsystem”, “Signal Specification” blocks which use bus objects as interface. You also need to check if you are performing signal routing using “From” and “Goto” blocks using bus objects.
- Check if the reference of your desired bus object is being used.
How can I programmatically find where a bus object is used across multiple models?
9 次查看(过去 30 天)
显示 更早的评论
I have a large set of custom library models using bus objects on interfaces. The bus objects are contained within a data dictionary that I am maintaining. I need to change a bus object definition, but I don't know all the places it is used in order to propogate the changes down in the models. Is there a way to search through multiple models at a time and find all the places a bus object is used?
I could just do a find_system for bus creators/selectors and ports and then find the assigned bus object, but would that catch all of the different uses of bus objects? Is there a better way?
0 个评论
回答(1 个)
Shubham
2024-2-23
Hi Jonathan,
It seems that you are trying to find all the places where the bus object is being used. I think you were on the right track to use the “find_system” function for finding the bus objects. You just need to be exhaustive in finding all the references of the object being used by the model.
To begin with finding buses used in a model, please refer to the following MATLAB Answer:
You need to perform a comprehensive search to find all the places where a bus object was being used.
Have a look at the following code snippet:
% Open the example model
model = 'sldemo_bus_arrays';
open_system(model);
load_system(model);
set_param(model, 'SimulationCommand', 'update');
busObjectName = 'sldemo_bus_arrays_busobject';
busUsage = {};
blocks = find_system(model, 'LookUnderMasks', 'all', 'FollowLinks', 'on', ...
'Type', 'block');
% Loop through each block and check relevant parameters
for i = 1:length(blocks)
blockHandle = get_param(blocks{i}, 'Handle');
blockType = get_param(blockHandle, 'BlockType');
% Depending on the block type, check different parameters
switch blockType
case 'BusCreator'
busObject = get_param(blockHandle, 'BusObject');
if strcmp(busObject, busObjectName)
busUsage{end+1} = [get_param(blockHandle, 'Parent'), '/', get_param(blockHandle, 'Name')];
end
case {'Inport', 'Outport'}
portDataType = get_param(blockHandle, 'OutDataTypeStr');
if contains(portDataType, busObjectName)
busUsage{end+1} = [get_param(blockHandle, 'Parent'), '/', get_param(blockHandle, 'Name')];
end
end
end
% Terminate the compilation of the model
set_param(model, 'SimulationCommand', 'stop');
% Close the model if you opened it with load_system
close_system(model, 0);
disp('Bus object usage:');
disp(busUsage);
You can generalize the above snippet to load multiple models and search through each block type. You could also search for the references for the bus object present in the Simulink data dictionary.
I hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Sources 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!