필터 지우기
필터 지우기

How to Make the Ports and Internal Variables of a FMU Block, Visible or Invisible?

조회 수: 48 (최근 30일)
Hadi Salimi
Hadi Salimi 2024년 7월 17일 18:08
편집: Hadi Salimi 2024년 7월 19일 12:24
I am using Matlab 2023a to insert an FMU block into my Simulink model with the following two lines of code:
>> addpath('path/of/the/fmu/file')
>> fmu_block = add_block('simulink_extras/FMU Import/FMU', 'MyModel/MyFMU', 'FMUName', 'fmu_file.fmu');
The FMU block is successfully inserted into my model, and everything is currently working well. When I double-click on the FMU block, I can see options to enable or disable the visibility of each output port and internal variable:
Now, I'm wondering how I can use a Matlab script to control the visibility of output ports or variables. I've already attempted to retrieve port information using get_param(...), such as this:
port_name = get_param('Model/FMU/1', 'Name');
But unfortunately, Matlab gives me this error:
Invalid Simulink object name: 'Model/FMU/1'.
Caused by:
'FMU' is not a SubSystem block.
Therefore, the question remains: How can I retrieve or modify the visibility parameter of the ports and variables within an FMU block? I would appreciate any assistance anyone can provide.

답변 (1개)

Anshuman
Anshuman 2024년 7월 18일 9:57
The error you encountered can happen if the path is incorrect or if the block does not support the operation you're attempting.
In Simulink, the path to a block should be specified using the full hierarchical path from the model root. For example, if your FMU block is inside a subsystem, you need to include the subsystem name in the path.
You can try doing something like this to retrieve or modify the visibility parameter of the ports within an FMU block:
% Correct path to the FMU block
fmu_block_path = 'MyModel/MyFMU';
% Retrieve all parameters of the FMU block
fmu_params = get_param(fmu_block_path, 'ObjectParameters');
%This will display a list of all parameters associated with the FMU block. Look for parameters related to the visibility of ports and variables.
% Assuming 'OutputPortVisibility' is a parameter for controlling visibility
current_visibility = get_param(fmu_block_path, 'OutputPortVisibility');
disp(current_visibility);
Hope it helps!
  댓글 수: 1
Hadi Salimi
Hadi Salimi 2024년 7월 19일 8:16
편집: Hadi Salimi 2024년 7월 19일 12:24
I've already checked the list of object parameters. The problem is that no such a property (or similar thing) exists, neither for FMU block itself not for its ports.

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

카테고리

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

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by