Skip to Main Content Skip to Search
Product Documentation

Interface to External Sources

Supported External Sources

Any source of data or code that is outside a Stateflow chart, its Stateflow machine, or its Simulink model, is considered external to that Stateflow chart.

Exported Data

You might want an external source (outside the chart and the model) to be able to access a data object. By defining the scope of a data object as Exported, you make it accessible to external sources. Exported data must be parented by the Stateflow machine, because the machine is the highest level in the Stateflow hierarchy and can interface to external sources. The Stateflow machine also retains the ability to access the exported data object. Exporting the data object does not imply anything about what the external source does with the data. It is the responsibility of the external source to include the exported data object (in the manner appropriate to the source) to make use of the right to access the data.

If the external source is another Stateflow machine, then that machine defines an exported data object, and the other machine defines the same data object as Imported. Stateflow software generates the appropriate export and import data code for both machines.

Exported Data Example

Suppose that you want to export a Stateflow data object named ext_data. Follow these steps:

  1. In your Stateflow machine, define data named ext_data of Exported scope.

  2. Define ext_data as imported in the external code source (custom code) using the following format:

    extern int ext_data;
    
    void func_example(void)
    {
    ...
    ext_data = 123;
    ...
    }

Stateflow software generates the following code for the exported data:

int ext_data;

Imported Data

Similarly, you might want to access a data object that is defined outside the chart and the model. If you define the scope of the data as Imported, you can access the data anywhere in the hierarchy of the Stateflow machine. The parent of an imported data object is external. However, the data object needs an adoptive parent to resolve symbols for code generation. The adoptive parent of an imported data object must be the Stateflow machine, because the machine is the highest level in the hierarchy and can interface to external sources. It is the responsibility of the external source to make the imported data object available (in the manner appropriate to the source).

If the external source for the data is another Stateflow machine, that machine must define the same data object as Exported. Stateflow software generates the appropriate import and export data code for both machines.

Imported Data Example

Suppose that you want to import a Stateflow data object named ext_data. Follow these steps:

  1. In your Stateflow machine, define data named ext_data of Imported scope.

  2. Define ext_data as exported in the external code source (custom code) using the following format:

    int ext_data;
    
    void func_example(void)
    {
    ...
    }

Stateflow software generates the following code for the imported data:

extern int ext_data;
  


Free Stateflow Interactive Kit

Learn how engineers use Stateflow to model state machines in their Simulink models.


Get free kit

Trials Available

Try the latest version of Stateflow.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS