How to make a bus object?

9 vues (au cours des 30 derniers jours)
David
David le 4 Août 2023
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

Réponses (2)

Daniel Bengtson
Daniel Bengtson le 4 Août 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 le 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.

Catégories

En savoir plus sur Composite Interfaces dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by