Using NI-DAQmx with the LabVIEW Simulation Interface Toolkit
Overview
The Simulation Interface Toolkit provides a link between The MathWorks, Inc. Simulink® software and LabVIEW. The Simulation Interface Toolkit enables control design engineers to run simulation models in the Simulink environment while using the power of a LabVIEW user interface to display results and modify parameters as the model runs. Using the Simulation Interface Toolkit, you can import a model developed using the Simulink environment into LabVIEW, where you can instrument the model with a variety of I/O devices.
The Simulation Interface Toolkit generates a set of custom LabVIEW VIs for each model. You can modify these VIs, called model and driver VIs, to interact with hardware, such as using NI-CAN to interface to a CAN network, or NI-DAQmx to use M-Series boards.
Note: The Simulation Interface Toolkit version 3.0 and later automatically generates code for NI-DAQmx IO. This document refers to implementing DAQmx support in earlier versions of this toolkit. To upgrade your existing version of the Simulation Interface Toolkit, contact National Instruments.
Table of Contents
Overview
The Simulation Interface Toolkit provides a link between Simulink software and LabVIEW. The Simulation Interface Toolkit enables control design engineers to run models developed using the Simulink environment while using the power of a LabVIEW user interface to display results and modify parameters as the model runs.In addition, you can use The MathWorks, Inc. Real-Time Workshop® software with the Simulation Interface Toolkit to generate a model DLL. Once you generate the model DLL, then you can run the model as a stand alone application in LabVIEW. Creating the model DLL enables you to run the model on an RT target for real-time, deterministic simulations. For example, you can use the model of a controller for prototyping or the model of the system for hardware-in-the-loop (HIL) testing. Both prototyping and HIL require I/O to read and generate signals. With the LabVIEW Real-Time Module, you have access to a wide variety of hardware for input and output; you can have a data acquisition card for analog, digital or counter signals, image acquisition, motion control, or communication through TCP/IP, serial or CAN.
NI-DAQmx API
There are different ways of interfacing your simulation models with the outside world. If you decide to use a data acquisition board, you might want to consider using the NI-DAQmx driver. NI-DAQmx is a multi-threaded, easy-to-use driver that implements advanced features which empower even more you data acquisition operations. With NI-DAQmx, you can create virtual channels, which are software entities that encapsulate the physical channel along with other channel specific information - range, terminal configuration, custom scaling, and so on - which formats the data. This allows you to measure signals from your application in a real world format: speed, acceleration, pressure, force, flow, etc.
One of the new features present in NI-DAQmx, inexistent in Traditional NI-DAQ, is the possibility of creating tasks. A task is an important new concept for NI-DAQmx. It is a collection of one or more virtual channels with timing, triggering, and other properties. Conceptually, a task represents a measurement or generation that you want to perform. For more information about NI-DAQmx, please consult the links provided below.
See Also:
Advantages of NI-DAQmx
Timing and Synchronization Features of NI-DAQmx
Modelname_daq_driver VI
When you build the model DLL using the Simulation Interface Toolkit and Real-Time Workshop, you get a set of model VIs and driver VIs that work with the SIT Server to call the model DLL and execute the simulation. The model VI for the data acquisition example is ModelName_daq_main.vi. This VI starts the SIT server and then calls ModelName_daq_driver.vi. The simulation takes place in the True case of the ModelName_daq_driver.vi.
There are three parts to this operation. The top row of VIs performs analog input, the middle row of VIs executes the model, and the bottom row of VIs performs the analog output. To use NI-DAQmx with this VI, replace the top and bottom rows of VIs with calls to NI-DAQmx. Each VI generated by the Simulation Interface Toolkit is customized to contain the correct model name and use the correct number of channels.
Complete the following steps to use the NI-DAQmx examples in this document.
- Download the VI provided.
- Open the VI and edit the Model DLL Name control so it matches the name of the DLL generated. Also set the names in the controls for the input and output channels. Make sure the total number of input channels match the number of inports in the model, and that the total number of output channels matches the number of outports in the model.
- Select Operate»Make Current Values Default from the top pull-down menu.
- Right-click the front panel to display the Controls palette.
- Select Select a Control. Navigate to model project folder, which contains the files generated in the build process.
- Select the ModelName_modelParamMapping.ctl.
- On the block diagram, wire the ModelName_modelParamMapping control to the mapping input of SIT Initialize Model VI.
- Save the VI.
- Open ModelName_daq_main.vi, and save it with a new name.
- In the second frame of the sequence structure, right-click the VI and select Replace»Select a VI.
- Select the VI you saved in step 8.
- You can now either use an existing host VI or create a new one using the SIT Connection Manager dialog box.
Refer to the Simulation Interface Toolkit User Guide for more information about creating a host VI using the SIT Connection Manager dialog box. You can reuse the same host VI with any of the new model VIs you generate. To use a new VI, select the VI saved in step 9 in the Path to Model VI path in the Select Host dialog box.
Notice how the model VI has the same form of the original Traditional DAQ VI. However, the main difference now is that it is using NI-DAQmx function calls instead of Traditional DAQ. Furthermore, you can modify the model VI so it will use DAQmx Global Channels instead of physical channels; that way, you can benefit from scaling and additional channel information.
Conclusion
You can modify the Simulation Interface Toolkit example VIs as shown in these examples to leverage your data acquisition operations. You can use a software timed loop, a hardware timed loop (counter), or a Timed loop structure depending on the needs of the application. The VIs described in this document serve as a starting point. You can expand the VIs to include more functionality. You also can modify the VIs generated by Simulation Interface Toolkit to include other types of hardware.
Simulink® and Real-Time Workshop® are registered trademarks of The MathWorks Inc.
Reader Comments | Submit a comment »
Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).


