How do you access the datatype of Bus Element Ports in MATLAB
8 views (last 30 days)
Show older comments
MathWorks Support Team
on 25 Jun 2024
Edited: MathWorks Support Team
on 9 Oct 2024 at 8:59
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?
Accepted Answer
MathWorks Support Team
on 9 Oct 2024 at 0:00
Edited: MathWorks Support Team
on 9 Oct 2024 at 8:59
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 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!