Access Custom Code Variables and Functions in Stateflow Charts - MATLAB & Simulink (original) (raw)

Main Content

You can integrate custom code written in C or C++ with Stateflow® charts in Simulink® models. By sharing data and functions between your custom code and your Stateflow chart, you can augment the capabilities of Stateflow and take advantage of your preexisting code. For more information, seeReuse Custom Code in Stateflow Charts.

Custom Code Variables in Charts That Use MATLAB as the Action Language

You can read and write the following C code variables directly in your charts that use MATLAB® as the action language.

Custom C Code Type Description
double Double-precision floating point
single Single-precision floating point
int8 Signed 8-bit integer
uint8 Unsigned 8-bit integer
int16 Signed 16-bit integer
uint16 Unsigned 16-bit integer
int32 Signed 32-bit integer
uint32 Unsigned 32-bit integer

By right clicking on the Stateflow object that uses your custom code, you can access your custom code variable. After right clicking on the object, hover over . Your custom code variable appears, denoted by (C variable). Clicking the C variable allows you to access the custom code from MATLAB.

Custom Code Functions in Charts That Use MATLAB as the Action Language

You can use the following C function argument types directly in your charts that use MATLAB as the action language without using coder.ceval. For information on calling external code from MATLAB code by usingcoder.ceval, see Call Custom C/C++ Code from the Generated Code (MATLAB Coder).

Custom C Function Argument Type Description
double Double-precision floating point
single Single-precision floating point
int8 Signed 8-bit integer
uint8 Unsigned 8-bit integer
int16 Signed 16-bit integer
uint16 Unsigned 16-bit integer
int32 Signed 32-bit integer
uint32 Unsigned 32-bit integer

By right clicking on the Stateflow object that uses your custom code, you can access your custom code function. After right clicking on the object, hover over . Your custom code function appears, denoted by (C function). Clicking the C function allows you to access the custom code from MATLAB.

Accessing Enumerations in Custom Code

To include enumerations from your custom code in charts that use C as the action language:

  1. Define your enumerations in a header file.
  2. Open the Configuration Parameters dialog box.
  3. In the Simulation Target pane, underAdvanced parameters, selectImport custom code.
  4. In the Code information tab, include the header file that defines your enumerations.

See Also

Topics