필터 지우기
필터 지우기

Programmatically get bus data type of In Bus Element block

조회 수: 35 (최근 30일)
Gergely
Gergely 2023년 7월 13일
편집: Gergely 2023년 8월 7일
I'm looking to get the bus data type used in 'In bus element' blocks in Matlab environment, e.g. using the 'get_param()' function or similar. The In Bus Element selects 1 element from the bus, but I'm not interested in the type of the element, but I need the bus type (name) of the associated parent bus.
What I'm trying to do is to list the root level ports and associated bus data types of a given model that uses only In Bus Element and Out Bus Element blocks with specified bus data types.
The bus element ports are mapped to an Autosar interface, I'm not sure if that changes anything.

채택된 답변

Gergely
Gergely 2023년 8월 7일
편집: Gergely 2023년 8월 7일
I have found a workaround solution with the help of Mathworks. If the In Bus Element does not select any element, it outputs the bus. So you can clear the selected element, and then access the bus type, and restore the element after.
inports = find_system('bustest_model','BlockType','Inport')
handle = getSimulinkBlockHandle(inports(1));
elem = get_param(handle,'Element');
set_param(handle,'Element','');
bustype = get_param(getSimulinkBlockHandle(inports(1)),'OutDataTypeStr')
set_param(handle,'Element',elem);

추가 답변 (1개)

Raghava S N
Raghava S N 2023년 7월 14일
To obtain the bus data type (name) of the associated parent bus from an 'In Bus Element' block in MATLAB, you can use the following approach:
  1. Identify the 'In Bus Element' blocks in your model: You can use the find_system function to find all the 'In Bus Element' blocks in your model. For example:
inBusElementBlocks = find_system('YourModelName', 'BlockType', 'Inport');
2. Get the parent bus object of each 'In Bus Element' block: Iterate through the 'In Bus Element' blocks and use the get_param function to retrieve the parent bus object. For example:
for i = 1:numel(inBusElementBlocks)
parentBusObject = get_param(inBusElementBlocks{i}, 'Parent');
% Perform further operations with the parentBusObject
end
3. Extract the bus data type (name) from the parent bus object: Use the get function to access the properties of the parent bus object and retrieve the bus data type (name). For example:
busDataType = get(parentBusObject, 'Name');
By following these steps, you can obtain the bus data type (name) of the associated parent bus for each 'In Bus Element' block in your model.
  댓글 수: 2
Gergely
Gergely 2023년 7월 14일
Sadly this did not work.
I have root level In Bus Elements, their parent refers to the model itself. The bus is defined as named datatype in the data dictionary of the model.
Here's a clarification of what it looks like:
The parent of this block is the model itself, which is not helpful for determining the bus data type.
>> get_param(gcb,'Parent')
ans =
'inbus_test'
Admasu Shewangizaw
Admasu Shewangizaw 2023년 7월 19일
I also needed to do this and no joy so far. The above method didn't work as stated by Gergely.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by