How do you access the datatype of Bus Element Ports in MATLAB
1 回表示 (過去 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!