How to make a bus object?

9 views (last 30 days)
David
David on 4 Aug 2023
Answered: Jaimin on 2 Sep 2024
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

Answers (2)

Daniel Bengtson
Daniel Bengtson on 4 Aug 2023
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);

Jaimin
Jaimin on 2 Sep 2024
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.

Categories

Find more on Composite Interfaces in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!