The ability to re-use existing code while migrating to a new test software framework can save developers both time and money. Both NI TestStand test management software and NI LabVIEW give users the ability to directly call and integrate with code written in a variety of languages such as Perl, Python and Tcl.
This article examines some of the more advanced scripting language concepts such as communicating with data acquisition devices and instruments. In particular, we will look at how to use Perl, Python and Tcl to call functions in DLLs, perform Data Acquisition using NI-DAQmx and communicate with instruments using NI-VISA.
The first section will describe how to call a function in a simple C-Style DLL from Perl, Python and Tcl.
We created a simple DLL using LabWindows/CVI that exports a single function called addNumbers. This function uses the cdecl calling convention and has the following four parameters and return value:
Prototype: int addNumbers (int x, int y, int* sum, char* string);
|x (in)||int (by value)||First Addend|
|y (in)||int (by value)||Second Addend|
|sum (out)||int * (by reference)||Output: Sum of x and y|
|string (out)||char * (by reference)||Output: “Hello World”|
|CVI Code: addNumbers|
|int addNumbers (int x, int y, int* sum, char *string)
*sum = x+y;
strcpy (string, "Hello World");
You can download the precompiled DLL here: simpledll.dll
NI-DAQmx is the high-performance, multithreaded, data acquisition (DAQ) driver software at the heart of NI measurement services software.
Installing the NI-DAQmx driver also installs and registers several DLLs. One such DLL is nicaiu.dll which is located at:
This particular DLL contains the function calls that are part of the NI-DAQmx C API. Script developers can use these functions to perform data acquisition using National Instruments DAQ devices.
You can find help on all of the NI-DAQmx C API functions in the NI-DAQmx C Reference Help which installs to:
Start»Programs»National Instruments»NI-DAQ»NI-DAQmx C Reference Help.
The following is a list of NI-DAQmx functions that are used will use in the following example scripts:
Note: All DAQmx functions return 0 on success. This example checks for zero at each step and reports an error for non-zero return values.
Detailed help on these functions can be found in the NI-DAQmx C Reference Help.
National Instruments Virtual Instrument Software Architecture (VISA) is a standard for configuring, programming, and troubleshooting instrumentation systems comprising GPIB, VXI, PXI, Serial, Ethernet, and/or USB interfaces. VISA provides the programming interface between the hardware and development environments.
Installing the NI-DAQmx driver also installs and registers several DLLs. One such DLL is visa32.dll which is located at:
This particular DLL contains the function calls that are part of the VISA C API, and developers can use these functions to perform instrument control.
You can find help on all of the VISA C API functions in the NI-VISA Help which installs to:
Start»Programs»National Instruments»VISA»Documentation»NI-VISA Help.
The following is a list of NI-VISA functions we will use in our example:
Note: All VISA functions return 0 on success. This example checks for zero at each step and reports an error for non-zero return values.
Detailed help on these functions can be found in the NI-VISA Help.
Now that you have learned the basics of data acquisition and instrument control in these three scripting languages, you are ready to create your own test automation software. To see more resources on National Instruments products and scripting languages click on the links below.
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.