1. Automating Access to Shared Libraries
Shared libraries are sections of precompiled code that are dynamically linked to the main program at run time. Windows Dynamic Link Libraries (DLLs), Linux Shared Libraries, and Mac OS Frameworks are all examples of shared libraries which you can access in LabVIEW using the Call Library Function Node. With this node, you can create an interface in LabVIEW to call existing or new libraries specifically written for use with LabVIEW. LabVIEW versions 8.2 and later include the Import Shared Library wizard, a powerful VI generation tool that substantially saves development time and decreases user error.
The Import Shared Library wizard automates the process of creating LabVIEW VIs that call third-party shared libraries. The generated VIs, or VI wrappers, each contain a Call Library Function Node that accesses a selected function from the shared library. This feature not only accelerates the process of integrating the shared library functions, but it also minimizes common user errors when configuring settings such as data formats, wiring, default values, and error handling.
The user-friendly wizard guides you through the process of setting up the Call Library Function Node and makes best guess choices for processing function parameters and handling errors. It also provides access to extensive configuration options for both global settings and individual VI settings.
2. Getting Started with the Import Shared Library Wizard
The Import Shared Library wizard requires a Windows .dll file, Linux .so file, or Macintosh .framework file and a corresponding header file. The wizard creates a LabVIEW project library that contains a set of wrapper VIs and an error report on the success of the VI generation.
3. Creating VI Wrappers for Shared Libraries
- Identify the shared library you want to access and the corresponding header file. The Import Shared Library wizard uses these files to create a LabVIEW project library (.lvlib ) file. The library contains the VIs that call the shared library functions. (For the purposes of this tutorial, you may use the attached files at the bottom of this document. This shared library contains basic calculator functions as well as callback functions that are explained in the header file.)
- Select Tools»Import»Shared Library to launch the Import Shared Library wizard.
Select Create VIs for a shared library to create a new LabVIEW project library or Update VIs for a shared library to update and existing project library. Click the Next button to continue.
4. Enter the path to the shared library file in the Shared Library (.dll) File text box, or click the Browse button to navigate to and select the file. If the header file is in the same folder as the shared library, the Import Shared Library wizard automatically fills in the path to the header file in the Header (.h) File text box. Otherwise, enter the path to the header file as well. Click the Next button to continue.
5. On the next page, enter any additional dependent files in the Include Paths field. Enter any other predefined symbols (preprocessor definitions) in the appropriate field. If you are using the attached shared library and header file, you do not need to enter any values in these fields. Click the Next button to continue and parse the header file.
6. The Import Shared Library wizard lists all the functions it finds in the header file. Select the functions for which you want to create wrapper VIs. Click the Next button to continue.
8. Select the Error Handling Mode you want the generated VIs to use. The Error Handling Mode determines how errors are displayed, when the error subVI is called, and whether or not LabVIEW calls a specific function if errors occur. For this exercise, select the Simple Error Handling method, which only calls the shared library if no errors occur before the VI runs. Click the Next button to continue.
9. On the next page, the wizard shows you the configuration of all of the function calls to the shared library. Select a function name and browse through the tabs to add documentation or change any settings.
Expand a function to view the configuration of the function parameters. Add documentation to the parameters or make modifications to the data types or how they are passed. The wizard automatically determines the appropriate data type for each parameter, but in some cases you might want to change the settings. For example, values passed by pointers cannot be identified as only an input or output and therefore are defined as both. Click the Next button to continue.
10. After the VI generation is complete, you can view an HTML report that LabVIEW creates and saves in the same destination directory as the project library file. This report indicate if any errors occured during the generation and suggests possible fixes for these errors.
11. Examine the generated VIs. The utility automatically creates meaningful icons for each function and documents the VIs using the information you entered in the wizard. If you wish to update the VIs, just run the wizard again and select the Update VIs for a shared library option.
In just a few easy steps, the Import Shared Library wizard helps you create VIs for shared library functions. This user-friendly interface minimizes room for error by automating VI wiring, data formats, default values, and error handling. Experienced programmers also have lower-level configuration capabilities for both global and individual VI settings. Use this powerful, time-saving tool to ease and improve shared library access for your LabVIEW application.