19. Linking with Reactis for C#

When generating C code from a model, both Simulink Embedded Coder and dSPACE TargetLink add comments which link the C code back to the model. Reactis processes these comments and uses them to build a map between the code and model components, which can then be used to explore and/or co-simulate a model and the C code generated from it. Linking a Reactis for Simulink session with a Reactis for C session lets you:

  • Click on a model item (block or Stateflow state or transition) to highlight corresponding C code,

  • Click on a line of C code to highlight corresponding model items,

  • Set a breakpoint in the model to set breakpoints on on corresponding C code,

  • Set a breakpoint on a line of C code to set breakpoints on corresponding model items.

19.1. Prerequisites for Use with Embedded Coder#

To use the linking feature with Embedded Coder, Reactis V2023.2 or later and Reactis for C V2023 or later are required. The C code must have been generated from the model using Simulink Embedded Coder. When generating code, the following settings must be set in the Comments tab of the model’s code generation settings:

  • Trace to model using must be set to Block path.

  • Stateflow object comments must be checked.

19.3. Enabling Linking with Reactis for C#

In both Reactis for Simulink and Reactis for C, linking must first be enabled before it can be used. To enable linking:

  1. In Reactis for Simulink, select File > Global Settings, then in the General tab, make sure the Allow connections between Reactis for Simulink and Reactis for C box is checked. You may additionally configure the range of TCP ports used for the communication. The setting Invoke Reactis for C version lets you configure which version of Reactis for C will be invoked by Reactis for Simulink.

  2. In Reactis for C, select File > Global Settings, then in the General tab, make sure Allow connections between Reactis for Simulink and Reactis for C is checked. The specified port range should match the one you gave for Reactis for Simulink.

Reactis for Simulink and Reactis for C must be restarted to make these changes take effect.

19.6. Embedded Coder Example Model and Code#

A sample model and corresponding code (generated by Embedded Coder) is included in the Reactis for Simulink distribution to facilitate testing the linking of Reactis for Simulink to Reactis for C.

19.6.1. Initial setup#

  1. Install Reactis for Simulink V2023.2 or later and Reactis for C V2023 or later

  2. Start Reactis for Simulink, select Global Settings > General, then:

    1. Make sure the Allow connections between Reactis for Simulink and Reactis for C check box is checked.
    2. Set Invoke Reactis for C version to the version of Reactis for C you have installed (V2023 or later).
    3. Click Ok.
    4. Exit Reactis for Simulink.
  3. Start Reactis for C, select Global Settings > General, then:

    1. Make sure the Allow connections between Reactis for Simulink and Reactis for C check box is checked.
    2. Click Ok.
    3. Exit Reactis for C.

19.6.2. Usage#

  1. Start Reactis for Simulink.

  2. Select File > Open Model.

  3. Select {REACTISROOT}\examples\R2020b\adaptive_cruise\adaptive_cruise.slx and click Ok.

  4. Select File > Invoke Reactis for C.

  5. Select {REACTISROOT}\examples\R2020b\adaptive_cruise\embedded_coder\adaptive_cruise.rsm and click Ok.

  6. Reactis for C will start and automatically link to Reactis for Simulink.

  7. You are now ready to try out the features listed in the Using the Link section above.