Call library function node labview example
Environment shows products that are verified to work for the solution described in this article. This solution might also apply to other similar products or applications.
Software
Programming Language
If you have code written in C, C++, or another programming language, you can utilize it in LabVIEW by calling the Dynamically Linked Library (DLL) that it is a part of. This tutorial explains different options for how to load DLLs into LabVIEW. This tutorial assumes familiarity with DLLs and their associated files.
Before you begin
- Is your library a C/C++ DLL , Microsoft .NET Assembly/.NET DLL or ActiveX DLL? To determine what type of library you have, you can check the Portable Executable (PE) header for the DLL files.
- If you are using a Microsoft .NET Assembly, continue to the Import .NET Assembly Functions with Constructor Node section below.
- If you are using an ActiveX DLLgo to section calling Active X.
- Do you have a header (*.h) file for your C/C++ DLL?
- If you do not have a header file, continue to the Manually Configure DLL Functions Using Call Library Function Node section.
- What data types does your function(s) utilize?
- If the function(s) you want to call utilizes supported data types, you can proceed with using the Import Shared Library Wizard. Continue to the Import Functions with Import Shared Library Wizard section.
- If your function(s) use complex or unsupported data types, you can use the Call Library Function node to import and format the functions manually. Continue to the Configure DLL Functions Using Call Library Function Node section.
To accompany the steps below, The LabVIEW Example Finder has complete and functional examples of how to properly call external code in LabVIEW. See Help >> Find Examples. >> Communicating with External Applications.
Import DLL Functions with Import Shared Library Wizard
If you have a header file and you are using supported data types, you can use the Import Shared Library Wizard to import your DLL functions into LabVIEW. This tool parses the header file, lists the functions in the shared library, converts data types in the shared library to LabVIEW data types, and generates a wrapper VI for each function. The wizard saves the VIs in a LabVIEW project library. Continue to the Use Header File with the Import Shared Library Wizard section.
A full set of instructions to configure the Import Shared Library Wizard is available in the LabVIEW Help. Briefly, you can start your import by:
- Launch LabVIEW and navigate to Tools >>Import. >>Shared Library (.dll) to launch the Import Shared Library Wizard.
- Select Create VIs for a shared library and then Next
- Input the file paths for the Shared Library (.dll) File and Header (.h) File.
- Continue configuring each page as needed, importing your desired functions, and selecting Next.
- When finished with configuration, select Finish to create your LabVIEW Project library (.lvlib) file.
For an example of how to import a DLL using the Import Shared Library Wizard, follow Example: Importing Functions from a Shared Library File from the LabVIEW Help.
Configure DLL Functions Using Call Library Function Node
If you do not have a header file or you are using unsupported data types in your C/C++ DLL, use the Call Library Function Node to manually pull in desired functions from the DLL and format the expected inputs and outputs.
- Launch LabVIEW and open a new VI.
- On the block diagram, add a Call Library Function Node and double-click the node to launch the configuration window.
- Configure the Call Library Function Node using the dialog box, pulling in the function and formatting input and output parameters.
- On the Function tab of the configuration window, enter the path to the DLL and select the function you wish to call.
- Navigate to the Parameters tab in the configuration window. Here you will add parameters and modify the return type until the function prototype at the bottom of the window matches the DLL's function definition.
- If the function(s) you wish to call contains complex data types, you'll need to manually define the function prototype within the configuration dialog in the Call Library Function Node (if the DLL has been compiled with a Type Library, the parameter data and return types will be defined automatically).
- Continue Configuring the Call Library Function Node using the dialog box with desired settings. When complete, select OK to update the Node on the block diagram to display the input and output terminals with the configured data types.
Import .NET Assembly Functions with Constructor Node
A .NET DLL, also called a .NET assembly, is useful in .NET programming. A .NET DLL uses the Common Language Runtime (CLR) and the .NET Framework to manage the functions within the DLL. You can use a .NET Constructor Node to put in the functions from a .NET Assembly.
- Launch LabVIEW and open a new VI.
- Add a Constructor Node to the block diagram.
- Use a Constructor Node in order to instantiate a class within the .NET assembly. This can be done by double-clicking the Constructor Node to bring up the Select .NET Constructor dialog box.
- Configure the Constructor Node using the dialog box based on the functions you are calling.
Use Property and Invoke Nodes to access properties and methods of the class by simply wiring in the class reference from the Constructor Node to the Property or Invoke Node.
Note: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.
Access examples of using the Constructor Node function in the LabVIEW Example Finder or in file path labview\examples\Connectivity\Dot NET.
Call Active X DLL using Active X functions:
1.- Locate the ActiveX functions in the LV functions palette->ActiveX
2.- Insert the Automation Ref function in order to get the automation reference for you ActiveX DLL.
3.- Use the Invoke Node to access the methods from your ActiveX DLL , use Property Node to access properties of your DLL.
4.-Close your Automation Ref to avoid memory leaks.