Building a LabVIEW UI for a Simulink® Model With LabVIEW Simulation Interface Toolkit

Updated Nov 18, 2020

Environment

Software

  • LabVIEW Simulation Interface Toolkit
  • LabVIEW

The Simulation Interface Toolkit (SIT) provides a seamless integration between The MathWorks Inc. Simulink® software and LabVIEW. The Simulation Interface Toolkit automatically generates LabVIEW code to interface with a Simulink® module resulting in a flexible and easy-to-use user interface. You first must configure the Simulink® model to communicate with LabVIEW. Then, you can create a LabVIEW host VI that automatically calls, runs, and interacts with the Simulink® model.


**Note: LabVIEW Simulation Interface Toolkit was discontinued in 2012 and replaced with the LabVIEW Model Interface Toolkit. If you are creating a new project to interface your Simulink model with LabVIEW, use the Model Interface Toolkit. If you are updating an older project, look to migrate from SIT to Model Interface Toolkit.**

Configuring the Simulink Model

Before LabVIEW can communicate with your Simulink® model, you must first correctly configure your model in Simulink®.
 

  1. Save the attached files sinewave.mdl and Sine Wave.VI.  

  2. Launch MATLAB® and notice how the MATLAB® command window displays the following message:
     

    Starting the SIT Server on port 6011
    SIT Server started

    The Simulation Interface Toolkit automatically installs the SIT server. If you do not see this message, the toolkit is not installed correctly

  3. Enter simulink in the MATLAB® command window to launch the Simulink® Library Browser window.
     

  4. Select File»Open and select the sinewave.mdl, downloaded in Step 1.  
     

    The simulation model should look similar to the following diagram:


     

    This Simulink® model represents a sine wave.  

  5. Note the SignalProbe block on the diagram.   You must place a SignalProbe block on the top layer of your diagram.  The SignalProbe block can be found in the NI SIT Blocks library.

  6. Also note the simulation settings by selecting Simulation>>Simulation parameters.   For information on setting the simulation options, refer to the LabVIEW 2010 Simulation Interface Toolkit Help.

  7. Save the Simulink® model

    You can now create a user interface in LabVIEW for the Simulink® model.  Notice that the model remains fully-operational within the Simulink® environment
     

Creating a LabVIEW User Interface

To interact with the Sine Wave Model using a LabVIEW user interface, you need to create a user interface in LabVIEW.
 

  1. Launch LabVIEW and open a new VI.

  2. Place two knob controls on the front panel.   Label one Frequency and the other Amplitude.

  3. Place a waveform chart on the front panel.   Label the y-axis Amplitude and the x-axis Time.
    Your front panel should look similar to the following Front Panel:


     

  4. You can now create the mappings between the VI and the Simulink® model. From the VI, select Tools>>SIT Connection Manager.

  5. In the Model and Host category, select Simulation Environment under Host Execution.  The execution host is the machine on which the SIT server is running.  If you want to select Real-Time Target or Driver VI on Local host, you must convert your Simulink® model to a DLL before you can create mappings.

  6. Under Current Model, select Browse and select the sinewave.mdl file.

  7. Under Project Directory, select Browse and select the folder in which you want your project to be contained. Ideally, this should be the same folder that you model is located in.  

  8. From the Category list, select Mappings to display the Mappings page.   The Current Mappings table shows the controls and indicators you created earlier on the front panel.  You will use this page to map your front panel items to the Simulink® model.


     

  9. Highlight the Frequency control in the Current Mappings table and click the Change Mappings button.  This will bring up the Specify Parameters for Control dialog box.  

  10. From this dialog box, select Frequency from the sinewave>>Sine Wave tree and click OK.


     

  11. Map the remaining objects.  Map the Amplitude control to the Amplitude from the sinewave>>Sine Wave tree. Map the Sine Wave indicator to the Port 1 from the sinewave>>Sum tree.  

  12. Click the OK button to close the SIT Connection Manager dialog box and generate the block diagram code for the VI. Notice there are now Model Controls on your front panel. You can use these controls to control the model from the VI.


     

  13. Notice the block diagram now contains code.  DO NOT MODIFY ANY of the code with green labels.  
     

You can run the VI and control the simulation with the Model Controls


The Frequency and Amplitude knob controls can be used to change the sine wave output.
 

This process described here does not require the MathWorks Real-Time Workshop®.  This VI uses Simulink® to run the simulation.  You also can use the Simulation Interface Toolkit together with the Real-Time Workshop® to build the model into a DLL for stand-alone simulation.  You need MATLAB®, Simulink®, and Real-Time Workshop® to build a model DLL and configure the user interface.  You need only LabVIEW to run the simulation.  For hardware-in-the-loop (HIP) and prototyping applications, you can run the model DLL in LabVIEW Real-Time to provide real-time inputs and outputs and to ensure determinism.


MATLAB®, Simulink®, and Real-Time Workshop® are registered trademarks of The MathWorks, Inc. Other product and company names listed are trademarks and trade names of their respective companies.