To download NI software, including the products shown below, visit ni.com/downloads.
This example is designed to illustrate the concept of using external code in LabVIEW. Specifically, this example demonstrates that LabVIEW allows a developer to use the code developed external to LabVIEW. This example contains a LabVIEW program that generates and sorts an array of numbers by calling a C-built DLL using LabVIEW's Call Library Function Node. This example also contains the C source code that the DLL was built from. It contains a .c file and a .prj file that can be build in LabWindows/CVI, as well as a .cpp file and all of the project files necessary to build this in Microsoft Visual C++. If you see a broken arrow when you open the LabVIEW VI, double-click on the Call Library Function Node and relink to the exact path of the DLL.
See also Calling a LabVIEW-built DLL in C to Acquire, Analyze, and Present Data. The material in Additional Information section below compares C and LabVIEW's functionality.
Building a shared library allows LabVIEW code to be shared and reused in other programming languages. callLVDLL.c, linked below, features a C program that calls functions from a LabVIEW-built DLL, LV_AAP.dll, to acquire, analyze, and present data. In order to make this example hardware independent, the “acquire” function does not actually acquire data but generates a sine wave. The “analyze” function computes the FFT Power Spectrum of the data, and the “present” function displays the data on a graph.
LV_AAP.DLL has been built from the VIs acquire.vi, analyze.vi and present.vi. The LabVIEW project LV_AAP.lvproj references these three VIs and includes the Build Specification required to create the DLL. With the project loaded you can examine how the DLL is created by expanding the Build Specification then right click on LV_APP and select Properties to view the Build Specification Properties dialog box for the DLL as shown in Figure 1.
Click the Source Files category to add VIs to be exported for the DLL. Each VI you add corresponds to one function called from an external environment. Click the Define VI Prototype button to display the Define VI Prototype dialog box shown in Figure 2. This dialog box allows you to define the function name, return type, and parameters of the DLL function. The parameters are generated automatically by clicking the Add button. The data types will be consistent with the VI connector terminals.
Select the Source File Settings category to configure the settings for each VI you want to include. To configure VI properties, click the Customize VI Properties button. In Figure 3, notice how the "Show front panel when called" setting is checked for "present.vi". This allows a user to view the front panel of "present.vi" and see the LabVIEW graph when they call a corresponding DLL function from another programming language. The other two VIs included in the DLL do not have this setting checked.
Click Build to generate a .dll file, a .h file, and a .lib file. These files make it easy to call the functions in the LabVIEW DLL. From a C environment, you can add the .lib and .h files to the project, include the .h file at the top of the source code, and put the labview\cintools folder in the include paths list to directly make the LabVIEW DLL function calls. Figure 4 shows the C function calls made to the LabVIEW DLL.
This example is designed to encourage you to use LabVIEW even if it cannot be the primary development environment.
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.