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

4 次查看(过去 30 天)
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
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
编辑:Hadi Salimi 2024-7-19
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.

请先登录,再进行评论。

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by