Compiling a Model from MathWorks Simulink® Software

Complete the following steps to convert your model you created in MathWorks Simulink® software into a compiled model that the Model Interface API can run.
Note   Before you complete this procedure, ensure your models are configured to interact with the Model Interface API the way you want.
1. Verify That the VeriStand Model Framework Is Installed

The VeriStand Model Framework must be installed on the computer with the Simulink software. The VeriStand Model Framework adds tools to the Simulink software that you use later in this procedure. More information.2. Ensure You Have the Correct Compiler

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

  1. What real-time operating system (RTOS) does my target run?Refer to the following KnowledgeBase at ni.com for a list of RT targets and the RTOS that each runs, then continue to step 2: What Operating System is my Real-Time Controller Running and Why? (Windows) If you want to create a compiled model that runs on Windows, just continue to step 2.
  2. Given the OS my target runs, what tools do I use to compile my model and what output do I create?
    Table 3.
    OS Required Tools Required Output Type
    Windows
    • Microsoft Visual C++
    • MathWorks Simulink ® Coder ™ software
    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 software
    .so
  3. Which versions of these tools are compatible with the version of the Model Interface Toolkit I am using?Refer to the following KnowledgeBase document at ni.com for a list of the versions of the LabVIEW, Windows, model compiler, and MathWorks software you can use with the Model Interface Toolkit: VeriStand Version Compatibility.

Related Links

  • KnowledgeBase at ni.com: Setting up MathWorks MATLAB® Software to Create a VeriStand Compatible DLL
  • KnowledgeBase at ni.com: Generating Models from MathWorks Simulink® Simulation Software for Deployment on NI Linux Real-Time Systems
Note   The Model Interface Toolkit shares several components with the VeriStand software, such as tools for compiling models designed in third-party modeling environments.
3. Select the Correct Compiler in MATLAB
  • (Windows) Run mex -setup in the MATLAB software and select the option number for a compatible version of Microsoft Visual C++.
  • (NI Linux Real-Time) Go to the next section. You do not need to select a compiler for NI Linux Real-Time when you install C/C++ Development Tools for NI Linux Real-Time, Eclipse Edition.
4. Build the Compiled Model in Simulink

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

  1. Launch the Simulink software and load your model you want to convert.
  2. Select Simulation»Model Configuration Parameters to launch the Model Configuration Parameters dialog box.
  3. Click the Solver tab and configure the following options:
    • Stop time: inf
    • Type: Fixed-step
  4. Click the Code Generation tab.
  5. Click the Browse button to launch the System Target File Browser dialog box.
  6. Select the correct option for your target from the list:
    • (ETS, Windows) NIVeriStand.tlc—NI Real-Time Target
    • (NI Linux Real-Time) 
      • (ARM-based targets) NIVeriStand_Linux_ARM_32.tlc—NI Real-Time Target
      • (Intel x64-based targets) NIVeriStand_Linux_64.tlc—NI Real-Time Target
        Note   The Model Interface Toolkit is not supported on x64 Intel-based cDAQ controllers running NI Linux Real-Time.
    Note   If the appropriate .tlc is not visible, the MATLAB software files might be read-only, and the Model Interface Toolkit installer is not able to provide this option. To display the option, add the following lines to the matlabrc.m file, a file that is installed by the MATLAB software:

    addpath('X:\VeriStand');

    NIVeriStandAddPaths;

    where X is the drive letter on which you installed the VeriStand Model Framework. The Model Interface Toolkit shares several components with the VeriStand software, such as tools for compiling models designed in third-party modeling environments.
  7. Click the OK button.
  8. Click the Build button in the Category section to begin building the compiled model. The MATLAB software command window displays the status of the build process. The following message in the MATLAB command window indicates that the Simulink Coder software has completed building the compiled model. ### Successful completion of build procedure for model:ModelName
Including External Source Code in the Compiled Model

If your model you are converting specifies any .c or .h files, you must specify the locations of these files so they are included in the compiled model. Specify the source files and include directories in the Simulink software, on the Code Generation tab of the Configuration Parameters dialog box.