How to add Get function to the Simulink model generated code

4 次查看(过去 30 天)
Hello,
I'm generation code from the Simulink model (2 inputs, three outpus). I'd like to add Get function for the output(s), e.g.:
RLS_OnOff LGTC_getRearLightOn(void)
{
return strVarRear.enuRearLightOn;
}
I tried it using Access Data Through Functions with Storage Class GetSet but not successfuly. In the Code Mapping, Data Defaults ribon, I updated Storage class for updates to the "GetSet". But during the code generation I received the folloiwng error message:
In model code mappings, default storage class for outports is set to 'GetSet', making generated code noncompliant with function prototype control feature. Set default storage class to 'Default'.
If I update it to Default to get rid of the error Get function is not created.
Does anybody know how to update the Code generation setting/code mapping to sucessfully build the model to get code containing the Get function for the output?
Thank you very much in advance

采纳的回答

MULI
MULI 2024-9-20
编辑:MULI 2024-9-20
Hi Oldirch,
I understand that you are encountering errors when trying to generate code from your Simulink model when including a ‘Get’ function for the outputs.
To address this error, you will need to manually implement the Get function in your code as follows,
  • Write a header file (e.g., foo.h) where you declare your Getfunctions as extern.
Example:
#ifndef FOO_H
#define FOO_H
extern RLS_OnOff LGTC_getRearLightOn(void);
#endif
  • In your source file, implement the ‘Get functions.
RLS_OnOff LGTC_getRearLightOn(void)
{
return strVarRear.enuRearLightOn;
}
  • Go to Configuration Parameters > Code Generation > Custom Code and include your header file by adding foo.h to include headers and set the correct path in include directories.
  • Also ensure that default storage class for outports is set to Default to avoid any errors.
By following these steps, you can manually create the Get functions and configure your project to include them.
For more details, you can refer to this MATLAB Answer where a similar query is addressed
  1 个评论
Oldrich
Oldrich 2024-10-8
Hi Muli,
actually we proceeded with the creation of the manually written code wrapper providing set/get functions for inputs/outputs of the automatically generated functions.
But I'll be more than happy to check the provided information and resources since it can definitely lead to further improvements.
Thank you, have a nice day!
Oldrich

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Deployment, Integration, and Supported Hardware 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by