How to add Get function to the Simulink model generated code

4 views (last 30 days)
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

Accepted Answer

MULI
MULI on 20 Sep 2024
Edited: MULI on 20 Sep 2024
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 Comment
Oldrich
Oldrich on 8 Oct 2024
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

Sign in to comment.

More Answers (0)

Categories

Find more on Deployment, Integration, and Supported Hardware in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!