Azzera filtri
Azzera filtri

Register datatype of inport in s-function

2 visualizzazioni (ultimi 30 giorni)
Karel Viaene
Karel Viaene il 6 Feb 2022
Risposto: Vidip il 20 Dic 2023
Hello,
I would like to link any signal to the inport of my s-function block and then use the ssGetDataTypeSize function onto the datatype of the inport to retrieve the size in bytes.
Currenlty I have a parameter on the s-function giving the name of the inport as a character array. For example 't_busTest'. Then I register that datatype in mdlInitializeSizes.
#define DATATYPE_CHAR (mxArrayToString(ssGetSFcnParam(S, 0)))
// Get data type of input and register
DTypeId idDataType; // = ssGetInputPortDataType(S, 0); (does not work)
ssRegisterTypeFromNamedObject(S, DATATYPE_CHAR, &idDataType);
Perferably, I would not need to have this parameter and I can retrieve the datatype from the inport, register it in the s-function and call the ssGetDataTypeSize. Is there a way to achieve this?
Thank you in advance!
Kind regards,
brecht

Risposte (1)

Vidip
Vidip il 20 Dic 2023
I understand that you want to link any signal to the inport of your s-function block and then retrieve the size based on the datatype.
You can use ‘ssGetInputPortWidth’, this function directly returns the number of elements in the data type of the specified input port. You can multiply this element count by the size of each element (known based on the data type) to get the total size in bytes and ‘ssGetInputPortDataType’ can be used to get the data type of the inport.
For further information, refer to the documentation links below:

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by