Getting 'empty' Compiled Port Data Types

I'm trying to write a script to get datatypes of an inport and a outport of a subsytem/block. When I run following command:
get_param(port_handle,'CompiledPortDataType')
an empty array/structure is returned. Model is compiled before running this command. 'CompiledPortDataDimensions' also returns an empty results.

1 个评论

I had similar issues in this Question. Never got it sorted out and never contacted Tech Support.
If you do get this sorted out, please post the solution either here and/or in the linked question.

请先登录,再进行评论。

 采纳的回答

Set model in compile mode to access data types
This may be changing, but historically at least, compiled port data types are available only when the model is actively in compiled mode.
mdl = 'fxpdemo_feedback';
open_system(mdl)
% "Lock" model in compiled mode
%
% NOTE: you will not be able to edit or even close model
% until compiled mode is terminated !!!
%
% TIP: Use try catch to avoid being unwittingly stuck in compile mode
%
try
eval([mdl,'([],[],[],''compile'')']);
blk1 = 'fxpdemo_feedback/A2D';
pdt1 = get_param(blk1,'CompiledPortDataTypes');
blk2 = 'fxpdemo_feedback/Controller/Combine Terms';
pdt2 = get_param(blk2,'CompiledPortDataTypes');
catch
end
eval([mdl,'([],[],[],''term'')']);
pdt1, pdt2
pdt1 = struct with fields:
Inport: {'double'} Outport: {'sfix8_En4'} Enable: [] Trigger: [] State: [] LConn: [] RConn: [] Ifaction: [] Reset: [] Event: []
pdt2 = struct with fields:
Inport: {'sfix32_En12' 'sfix32_En12'} Outport: {'sfix32_En12'} Enable: [] Trigger: [] State: [] LConn: [] RConn: [] Ifaction: [] Reset: [] Event: []

3 个评论

Hi Andy,
Is there a doc page that discusses the usage of the command that's being evaluated by the eval statement?
Could
set_param(mdl,'SimulationCommand','compile')
be used instead?
The doc (2021b) has the Description of CompiledPortDataTypes as: Data types of port signals after updating diagram. You must compile the model before querying this property.
In the past, I guess I didn't appreciate what "compile" means in this context. I'm sure I read "must compile" as the compilation must be complete (and I guess I assumed that was done automatically as when simulation is updated or run), but you're saying that it might be more accurate to say: "The model must be in compiled mode when querying this property."
Determine Signal Dimensions suggests another strateg for getting the Compiled* block properties is to start the simuation and pause it, or take a step, and then get the Compiled* properties. Is that a viable alternative to the eval approach? If so, is the simulation in a compiled mode when it's paused?
1) Yes, there is definitely a more modern syntax to get into compiled mode that what I should. The command you gave looks correct (but I didn't test it).
2) Yes, "must be in compiled mode" is more correct / clearer IMHO.
3) Yes, when stopped in the Simulink debugger, the model should still be "in compiled mode."
Hi Andy,
Thanks for the response. It turns out that this command
set_param(gcs,'SimulationCommand','compile');
results in an error.
Do you know if there is a doc page that discusses all of the valid setting for SimulationCommand? I can only find example uses, but not a complete list.

请先登录,再进行评论。

更多回答(1 个)

Run the model once (insted of just compiling) and check if model generates any data from ports and call or run the command
get_param(port_handle,'CompiledPortDataType')
Possibly no data might have been generated by model

4 个评论

If you have run the model and the problem still persists,in that case check whether the I/O ports are connected to model correctly
@VBBV, Thanks for your reply. I have tried running model also. Stil not getting desired data. About ports connection, they are connected properly. This is a working model.

Ok. Test your model with valid inputs or input range. Before running your model, check simulation settings also e.g. time scale for simulation etc. A reasonable time duration. If the same problem exists then verify for any model inconsistencies.

BTW , how is the data being read from I/O ports ? Do you use read or some other functions to read data from ports ?

Hi @VBBV,
This model is interfaced with other model for reading data. Even if I connect a constant block to inport of model or any subsystem inside model, I dont get the compiled data types. I receive following output after running command:
get_param(outports,'CompiledPortDataType')
ans =
3×1 cell array
{0×0 char}
{0×0 char}
{0×0 char}
I even tried creating a simple test model (few inports, outports and a subsystem) and check for this command. It is not working in new model also. I'm not sure if I'm getting a correct port handle. I'm running following commands in order:
sys = get_param('test1','Handle');
list_of_subsystems = find_system(sys,'BlockType','SubSystem');
ports = get_param(list_of_subsystems(1), 'PortHandles');
inports = ports.Inport;
get_param(inports,'CompiledPortDataType')
Is there any other way to get port handles and read datatype? I would like a way to specify the model name (not the way using 'gcbh').

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Manual Performance Optimization 的更多信息

产品

版本

R2020b

标签

Community Treasure Hunt

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

Start Hunting!

Translated by