How to change the name of external inputs/outputs in generated code?

17 ビュー (過去 30 日間)
Maksim Sorin
Maksim Sorin 2022 年 11 月 23 日
回答済み: Rajanya 2024 年 9 月 16 日
Hello all, I am using embedded coder and I cannot figure out how to change a default on the generated code. Every time my code generates I get something like this:
typedef struct {
real32_T In1; /* '<Root>/In1' */
real32_T In2; /* '<Root>/In2' */
real32_T In3; /* '<Root>/In3' */
} ExtU;
Invalid use of operator.

Error in connector.internal.fevalMatlab

Error in connector.internal.fevalJSON
Now majority of this is just fine, but I want the ExtU to be auto generated with ExtU_FileName. I cannot find a setting to modify that. Same goes for the output struct. I want it to be ExtY_FileName
/* External outputs (root outports fed by signals with default storage) */
typedef struct {
real32_T out1; /* '<Root>/out1' */
real32_T out2; /* '<Root>/out2' */
} ExtY;
The reason I need this is I am using quite a few generated code files and for clarity I want the structures to be associated with the file names. How can I go about doing this without modifying the code by hand?

回答 (1 件)

Rajanya
Rajanya 2024 年 9 月 16 日
I was able to reproduce the issue on an example Simulink model. The structures generated were as follows:
For such cases, you can change the identifier configuration to get all the identifiers in the desired configuration.
Simulink allows you to specify the format in which the identifiers (variables) would be named in the generated code by going to Model Properties > Code Generation > Identifiers and setting the different types of identifiers.
For this issue, you can change the ‘Global Types’ identifier format to ‘$N$R$M_T’. The ‘$R’ token inserts ‘root model name’ into the identifier which, in this case, is desired. The ‘$N’ token was already being generated before as it corresponds to the name of the object for which the identifier is generated.‘$M’ handles the name-mangling to prevent naming conflicts.
For example, using the example model (called "testit") mentioned above and setting the format as above, the structure names changed as shown below.
Check out this documentation page for the different tokens that can be used in Identifier Format Control and their respective descriptions:
Hope this helps!

カテゴリ

Help Center および File ExchangeDeployment, Integration, and Supported Hardware についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by