Azzera filtri
Azzera filtri

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

49 visualizzazioni (ultimi 30 giorni)
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.

Risposte (1)

Anshuman
Anshuman il 18 Lug 2024 alle 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 Commento
Hadi Salimi
Hadi Salimi il 19 Lug 2024 alle 8:16
Modificato: Hadi Salimi il 19 Lug 2024 alle 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.

Accedi per commentare.

Categorie

Scopri di più su Event Functions in Help Center e File Exchange

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by