Compiling a Model from MathWorks Simulink

Convert MathWorks Simulink models into compiled models compatible with the Model Interface API.

Note Before you complete this procedure, ensure that you configure your models to interact with the Model Interface API the way you want.
  1. Verify that the VeriStand Model Framework is installed. The VeriStand Model Framework adds tools to Simulink that you can use later in this procedure.
  2. Ensure you have the correct compiler.

Answer the following questions to determine which tools you must use to convert and compile Simulink models:

  • What Real-Time Operating System (RTOS) does my target run?—For more information on RT targets and the RTOS that each runs, see the Real-Time Controllers and Real-Time Operating System Compatibility knowledge base article at ni.com.
  • Given the operating system my target runs, what tools do I use to compile my model and what output do I create?

    You can use the following compilers with various operating systems:

    Table 2. Model Compilers
    Operating System Required Tools Required Output Type
    Microsoft Windows
    • Microsoft Visual C++
    • MathWorks Simulink Coder
    Note VeriStand 2015 also supports the older version of the Simulink Coder, called the Real-Time Workshop.
    .dll
    NI Linux Real-Time
    • C/C++ Development Tools for NI Linux Real-Time, Eclipse Edition
    • MathWorks Simulink Coder
    .so
  • Which versions of these tools are compatible with the version of the Model Interface Toolkit I am using?—For a list of the versions of the LabVIEW, Windows, model compiler and MathWorks you can use with the LabVIEW Model Interface Toolkit, see the VeriStand Model Generation Support and MathWorks Simulink Compatibility knowledge base article at ni.com.
    Note

    The LabVIEW Model Interface Toolkit shares several components with the VeriStand, such as tools for compiling models designed in third-party modeling environments.

    For more information, see the following knowledge base articles at ni.com:

    • Creating Simulation Models Using NI VeriStand Model Framework
    • Generating Models from The MathWorks, Inc. Simulink Software for Deployment on NI Linux Real-Time Systems
    .
  • Select the Correct Compiler in MATLAB

  • Windows—Run mex -setup in the MATLAB software. Select the Microsoft Visual C++ version.
  • NI Linux Real-Time—You do not need to select a compiler for Linux Real-Time if you install C/C++ Development Tools for Linux Real-Time, Eclipse Edition.
  • Build the Compiled Model in Simulink

    After you select and set up the correct compiler, complete the following steps to build the compiled model:

    1. Launch Simulink.
    2. Load the model you want to convert.
    3. Select Simulation » Model Configuration Parameters to launch the Model Configuration Parameters dialog box.
    4. Click the Solver tab.
    5. Configure the following options:
      • Stop time: inf
      • Type: Fixed-step
    6. Click the Code Generation tab.
    7. Click the Browse button to launch the System Target File Browser dialog box.
    8. Select the correct option for your target from the following list:
    9. ETS, WindowsNIVeriStand.tlc—NI Real-Time Target
    10. NI Linux Real-Time
    11. ARM-based targetsNIVeriStand_Linux_ARM_32.tlc — NI Real-Time Target
    12. Intel x64-based targetsNIVeriStand_Linux_64.tlc — NI Real-Time Target
    13. Note x64 Intel-based cDAQ controllers running NI Linux Real-Time do not support the LabVIEW Model Interface Toolkit.
    14. Note If the appropriate .tlc is not visible, the MATLAB files might be read-only, and the LabVIEW Model Interface Toolkit installer is not able to provide this option. To display the option, add the following lines to the matlabrc.m file that is installed by the MATLAB:

      addpath('X:\VeriStand');

      NIVeriStandAddPaths;

      Where X is the drive letter on which you installed the VeriStand Model Framework.
    15. Click the OK button.
    16. Click the Build button in the Category section to build the compiled model. The MATLAB command window displays the status of the build process. The following message in the MATLAB command window indicates that the Simulink Coder has completed building the compiled model: ### Successful completion of build procedure for model: ModelName.

    Including External Source Code in the Compiled Model

    If the model you are converting specifies any .c or .h files, you must specify the locations of the files to include them in the compiled model. To specify the source files and include directories in Simulink, go to the Configuration Parameters dialog box on the Code Generation tab.