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!