19. Linking with Reactis for C#

When generating C code from a model, Simulink Embedded Coder adds comments to link the C code back to the model. Reactis now leverages this instrumentation to help you explore and 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#

To use the linking feature, 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.2. 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 C and Reactis for C must be restarted to make these changes take effect.

19.5. Example Model and Code#

A sample model and corresponding code is included in the Reactis for Simulink distribution to facilitate testing the linking of Reactis for Simulink to Reactis for C.

19.5.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: a. Make sure the Allow connections between Reactis for Simulink and Reactis for C check box is checked. b. Set Invoke Reactis for C version to the version of Reactis for C you have installed (V2023 or later). c. Click Ok d. Exit Reactis for Simulink

  3. Start Reactis for C, select Global Settings > General, then: a. Make sure the Allow connections between Reactis for Simulink and Reactis for C check box is checked. b. Click Ok c. Exit Reactis for C

19.5.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.

_images/rfcLinkingDemo2.png

Fig. 19.2 Code highlighting after clicking on a Stateflow transition.#

_images/rfcLinkingDemo1.png

Fig. 19.3 Model highlighting after clicking on a C code line affecting multiple model blocks.#