Importing MathWorks Simulink components

To import a MathWorks Simulink component, you must do steps in Simulink and in IBM® Engineering Systems Design Rhapsody®.

In MathWorks Simulink

Procedure

  1. Create a MathWorks Simulink model, or open an existing one, and save it in your working directory, preferably in the same working directory as your Rhapsody model.
  2. For generating code, use the following settings (most are the default settings) in the Simulink Coder. You can view the settings by selecting Simulation > Model Configuration Parameters.
    • Hardware Implementation->Device Type - Unspecified (assume 32-bit Generic)
    • Code Generation->System target file - ert.tlc
    • Code Generation->Language - C or C++ (note that the default setting is C)
    • Code Generation->Make command - make_rtw
  3. Generate code for the Simulink model by carrying out the following steps on the Model Configuration Parameters page.
    1. Select the Generate code only option.
    2. Click Generate Code.

In Rhapsody

Procedure

  1. Create a Rhapsody project.
  2. Right-click the project name in the browser and select Add to Model > Package.
  3. On the Add to Model window, navigate to <Rhapsody installation folder>\Share\Profiles\Simulink and in the Files of type field, select Package (*.sbs).
  4. Select the SimulinkInC.sbs profile if you are using C and Simulink.sbs if you are using C++. Click Open to add the selected profile to the project. Check the Profiles section in the browser to be certain that the selected Simulink profile is now displayed.
  5. Create an object in an object model diagram, and apply the SimulinkBlock stereotype to it (in the Features window).
  6. Right-click the object and select Import/Sync Simulink Model.
  7. In the window that is displayed, provide the following information:
    • Simulink Model File. The location of the Simulink model file
    • Simulink Generated Source Code. The location of the *.cpp files generated by the Simulink Coder (add all files except ert_main.cpp).
    • Simulink Model Sample Time. The interval (in milliseconds) at which Rhapsody activates the Simulink engine.
  8. Click Import/Sync and wait until Rhapsody creates flowports on the block representing the input and output of the Simulink model.
  9. Once the flowports have been created, you can connect the Simulink block to the flowports on other Rhapsody blocks.

Integration of the Simulink-generated code

About this task

When Simulink components are imported into a Rhapsody model, the .cpp files generated from the Simulink model using Simulink Coder are included as source files in the Rhapsody‑generated makefile.

In terms of Rhapsody‑generated code, SimulinkBlock elements in Rhapsody are classes that are based on a framework class called OMSimulinkBlock. The superclass periodically calls the method doStep(), which is implemented by the derived class. This method initializes the input port, calls the step function in the Simulink‑generated .cpp file, and sets the value of the output after the step. (The output is then relayed through the output flow port.)

The doStep() function will be generated once you assign the SimulinkBlock with a Simulink model and use the Import/Sync Simulink Model menu command. Note that an Embedded Coder License (ERT) is required for this operation.

Troubleshooting the integration of Simulink models

About this task

  • If after importing or synchronizing with your Simulink model, you get an error message about a missing file, langeng.dll, verify that the MATLAB \bin\win32 folder is in your PATH environment variable. After adding it, you will have to restart Rhapsody and try reimporting.
  • If you get compilation errors regarding missing include files, look for them in the MATLAB installation directory. After locating them, you can add them to the include search path for the Rhapsody configuration.