How to make a bus object?
10 次查看(过去 30 天)
显示 更早的评论
I have a library that I want to feed a bus into. I think I need to change my inport to a bus data type so that it knows what to expect in terms of signal names. However, when I select Bus: <object name>, I don't have an object name to give it. I'm assuming I need to have a .m file somewhere in the workspace with a bus data type that I created? How do I do this? Thanks
0 个评论
回答(2 个)
Daniel Bengtson
2023-8-4
Something like this should work.
function create_Buses()
% Bus object
clear elems;
elems(1) = Simulink.BusElement;
elems(1).Name = 'BusSig_1';
elems(1).Dimensions = 1;
elems(1).DimensionsMode = 'Fixed';
elems(1).DataType = 'uint32';
elems(1).SampleTime = -1;
elems(1).Complexity = 'real';
elems(1).Min = [];
elems(1).Max = [];
elems(1).DocUnits = '';
elems(1).Description = '';
elems(2) = Simulink.BusElement;
elems(2).Name = 'BusSig_2';
elems(2).Dimensions = 1;
elems(2).DimensionsMode = 'Fixed';
elems(2).DataType = 'uint32';
elems(2).SampleTime = -1;
elems(2).Complexity = 'real';
elems(2).Min = [];
elems(2).Max = [];
elems(2).DocUnits = '';
elems(2).Description = '';
elems(3) = Simulink.BusElement;
elems(3).Name = 'BusSig_3';
elems(3).Dimensions = 1;
elems(3).DimensionsMode = 'Fixed';
elems(3).DataType = 'uint8';
elems(3).SampleTime = -1;
elems(3).Complexity = 'real';
elems(3).Min = [];
elems(3).Max = [];
elems(3).DocUnits = '';
elems(3).Description = '';
BusData = Simulink.Bus;
BusData.HeaderFile = '';
BusData.Description = '';
BusData.DataScope = 'Auto';
BusData.Alignment = -1;
BusData.Elements = elems;
clear elems;
assignin('base','BusData', BusData);
0 个评论
Jaimin
2024-9-2
Hi @David
Based on the issue description provided, I understand that you want to use the "inport" block to pass a bus as an input.
Bus data can be imported to top-level input ports by manually specifying the data in the Input configuration parameter or by using the Root Inport Mapper tool.
Please follow this Mathwroks Documentation page to accomplish that.
Load Bus Data to Root-Level Input Ports:
I hope this will resolve the issue.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Composite Interfaces 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!