How to get Port Data Type inside a Masked Block
13 views (last 30 days)
Show older comments
I have the need to programmatically use the data type information at the input to a mask, for Fixed Point processing.
This information is clearly available to the model somehwere, since doing an Update (Ctrl-D) will show the fixed point precision above the ports (ie: sfix16_En15). It is not clear where to retrieve this information, though. Originally, I tried getting the CompiledPortDataTypes property in the StartFcn() callback, but it appears that an explicit 'compile' command has to be issued, per the information below.
Explicitly compiling is not an option to call from a masked subsystem initialization routine.
Please note, I'm looking for a way NOT to have to compile to get this information Is there a way?
Thanks for the help.
------------------------
Note: I've seen this thread: http://www.mathworks.com/matlabcentral/answers/8679-how-to-get-the-port-types-and-dimensions-for-a-block
as well as the documentation that states the need to compile a model:
CompiledPortComplexSignals:
Complexity of port signals after updating diagram. You must compile the model before querying this property. For example:
vdp([],[],[],'compile');
d = get_param(gcb,'CompiledPortComplexSignals');
vdp([],[],[],'term');
CompiledPortDataTypes:
Data types of port signals after updating diagram. You must compile the model before querying this property. See CompiledPortComplexSignals.
0 Comments
Answers (3)
Zack Peters
on 24 Oct 2013
Hi Timothy,
Unfortunately, the 'CompiledPortDataTypes' parameter is the only parameter that will give you the data types at each of the ports. As you already discovered, this option will require the model to be in a compiled state for you to grab that information.
The reason for this being that block diagram may contain many blocks which will inherit their data types from upstream or downstream blocks. The model does not repeatedly recompute this information every time a block is added or removed within the block diagram as this can become a costly process.
In some cases you may be able to know the data type based on the context. Some blocks (such as a constant) have an 'OutDataTypeStr' property which you can use to explicitly know the data type. Similar blocks such as the Inport/Outport and Data Type Conversion blocks are also able to specify the data types at input or output ports.
Perhaps giving a more specific example of what you are trying to gain by knowing the data type would allow someone to provide an alternative workaround to get to the end goal.
~Zack
3 Comments
Zack Peters
on 8 Nov 2013
Hi Timothy,
You may not notice is when you press Control-D as it may be quite quick for some models, but the Simulink engine goes through quite a bit of computation before it shows up on the screen and I can assure you quite a bit is going on in the engine before it gets to the point of showing the data types in your model.
Our Fixed Point Designer has a feature which allows you to look at all of the data types in the model, convert them to fixed point (if not already converted) and given a predefined input test vector to your model, makes accurate fraction/word length based on the ranges/accuracy of the desired blocks. You have full control over this process through all sorts of customizations so you can manually control the fixed-point data types being selected at any given point.
Its been my experience that the designer is going to do a better job at optimizing than most individuals and you can always manually override anything if it doesn't fit your specifications.
~Zack
Andy Bartlett
on 9 Feb 2018
Hi, There is no way to get this information up to the Mask initialization code a compile time, but blocks under the mask can see this information as it comes to their ports.
The data type propagation block provides a way to control propagation with out creating a new block. https://www.mathworks.com/help/simulink/slref/datatypepropagation.html
The key "trick" is to set the output data type of the block it is controlling to inherit via back propagation.
To see an example of this, do hilite_system('fixpt_dtprop/FixPt Strip Scaling') then look under the mask of that block.
For much more depth on propagation, you can down load this material https://www.mathworks.com/matlabcentral/fileexchange/56786-tutorial-on-simulink-data-type-propagation-engine and search the web for a corresponding video
Regards Andy Bartlett
0 Comments
Sylvain R.
on 17 Jan 2019
Hello,
I'm facing the same issue.
My library block contains an HDL blackbox. The input bit sizes of the HDL Blackbox is dynamic (using HDL Generic parameters). The library block has a mask, letting the user select the signals data type.
I need to know the data type of the Simulink block input, to estimate the number of bits required for encoding it and set the HDL Blackbox generic parameter to the appropriate value.
This information is available at the end of the Diagram Update as it is shown on screen. So, five years later, is there any way to obtain this information in the mask callbacks? Any function, property of block one could use to retrieve this information? Maybe during the Ctrl-D, the block DataTypePropagation has a usefull property?
Alternatively, a solution would be to duplicate the Data type information, once in a user-dedicated popup, once in a non-enabled parameter which gets updated during some script-"compile" execution.
0 Comments
See Also
Categories
Find more on Data Types in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!