How do you access the datatype of Bus Element Ports in MATLAB
조회 수: 9 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2024년 6월 25일
편집: MathWorks Support Team
2024년 10월 9일
I have a model that outputs a Bus of type 'TestBus'. The Bus is comprised of three Doubles, which I define and output using 'Bus Element Outports'.
I would like to access the output datatype of my entire model (which is a 'TestBus'). However, when I access the datatype of the Bus Element Outports, I receive 'Double' instead of 'TestBus'.
For instance, the following code returns 'Double' on my compiled model:
get(<Bus Element Handle>,'CompiledPortDataTypes').Inport{1}; % Returns Double, should return TestBus
How can I access the Bus output datatype of my Bus Element Ports?
채택된 답변
MathWorks Support Team
2024년 10월 9일
편집: MathWorks Support Team
2024년 10월 9일
In order to get the Bus datatype of the Bus Element Outports, you must use the complete path of the port rather than the complete path of the block.
get_param(<Path to Port>,'OutDataTypeStr') % returns 'Bus: TestBus'
In order to get the path to your port, you can double click on your Bus Element Block to open its properties -- at the top, you will see a 'Port name' text box. Alternatively, you can programmatically access the 'Port name':
pathToPort = [get(<Block Handle>,'Path'), '/', get(<Block Handle>,'PortName')]
dataType = get_param(pathToPort, 'OutDataTypeStr');
If you need to get the block handle for a 'Bus Element In', this can be done the following way:
inBusElementBlocks = find_system('yourModel', 'BlockType', 'Inport')
% select one of your in bus
inBus = inBusElementBlocks(4);
handle = getSimulinkBlockHandle(inBus);
pathToPort = [get(handle,'Path'), '/', get(handle,'PortName')];
dataType = get_param(pathToPort,'OutDataTypeStr')
If you are looking to get the output datatype of normal Outports, you must follow your original method, using the 'CompiledPortDataTypes' property.
댓글 수: 0
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!