How LabVIEW & Python Are Better Together

Both LabVIEW and Python are indispensable tools when it comes to development and programming. With so many strengths and benefits to both- how do you decide which one to use? The answer is simple. You don’t need to choose! LabVIEW and Python work even better together when it comes to automating test systems. In a recent webinar, NI product marketing engineer Austin Stanton put these complementary capabilities on display.

Using LabVIEW and Python Together

LabVIEW’s Strengths:
The first topic covered in the webinar are the individual strengths of both LabVIEW and Python. For instance, it is incredibly easy to integrate hardware with LabVIEW, thanks in part to the over 7,000 pre-made hardware instrument drivers that are available on the NI site. LabVIEW also offers both Real Time and FPGA Modules, which make usually complicated applications much more approachable. LabVIEW is also a great asset for inexperienced users with its built-in multi-threading support and drag-and-drop front panel design that allows you to create a sleek user interface without a lot of effort.

Python’s Strengths:
The first strength of Python that Stanton points out is that it has created a large community with tons of forums. If you have questions or are stuck with some code, answers and support are readily available. Python is also incredibly portable- one piece of code can work and scale across a large range of architectures (like ARM) and multiple operating systems. Python also has a large set of powerful packages and libraries which assist with the complicated applications of topics such as Artificial Intelligence and machine learning. Of course, Python is also a great tool because it is completely free.

Stanton goes on to explain that Python and LabVIEW are a great example of NI’s belief in always having the “right tool for the right job”. When used in tandem, Python is able to do the things LabVIEW can’t do easily, such as scripting and web applications. It can be incredibly helpful in writing applications for Raspberry Pi, or another ARM architecture that LabVIEW is not proficient with. Put simply. LabVIEW does its job incredibly well, and creates a great foundation for Python to build on!

2 Main Approaches to Integration

Calling LabVIEW from Python
The integration approach is best used if LabVIEW is just a small step in the overall process of what you are trying to accomplish, like if you have Python code and want to use LabVIEW as a virtual instrument (VI) for something specific. For example, if you had Python set as test executive and Labview either working with an instrument or data logging, you could call the LabVIEW VI from the Python code and have it execute- allowing you to look over the collected values before closing it out.

More information about this approach can be found on this helpful Github page.

Calling Python from LabVIEW
In the webinar, Stanton spends the most time focused on this integration approach by going through a demonstration on how Python and LabVIEW can be used collaboratively within a validation test workflow.

There are several different steps you usually take in a validation test system, the first being that you want to somehow be able to control and communicate with it whatever device you are testing. Once that is established, you want to acquire some sort of data from the device. Depending on the type of device, this step uses sensors to collect various measurements. Next, you want to log the data you collect and then run analysis on it (often resulting in a pass or fail). Finally, you want to share that data with someone- either the technician or your colleagues.

In the demonstration, Stanton uses an Arduino as the Device Under Test (DUT). The goal is to collect temperature data, convert it from Celsius to fahrenheit, and then share it via Python to Microsoft Teams. A cDAQ Chassis with a digital I/O module is used to read from the digital I/O channel that is being toggled on the Arduino. A thermocouple input module is also used, to read the temperature of the microcontroller using a thermocouple.

The logging of data from the demo is done in LabVIEW, which is in control of the cDAQ Chassis. The temperature conversion is completed by Python.

Screenshot of the LabVIEW and Python demo, courtesy of NI
From the “LabVIEW versus Python: Why not Both?” Webinar from NI

The Digital I/O Module in the cDAQ Chassis is wired to the first channel of the DIO line that is being toggled, and since LabVIEW is controlling that, it is able to graph that change each time the “DUT control” button is pressed. The temperature control loop is reading from the thermocouple input, while the thermocouple itself is attached to the microprocessor of the Arduino.

Screenshot of the LabVIEW and Python demo, courtesy of NI
From the “LabVIEW versus Python: Why not Both?” Webinar from NI

The data processing loop is routing the temperature value in Celsius to a conversion loop, where a Python node and some function script will convert the values to Fahrenheit. The conversion is done in a separate loop to avoid delays in the processing temp data.

Finally, the data of the demo is saved to a file located in OneDrive. Using a shared data function in the Python code, the link/URL to the OneDrive folder is then sent into the specified Teams channel.

While this demo seems simple enough, Stanton gives a real-world example with the same principles. A company used a cDAQ with 8 thermocouples attached to the outside of a pipe. Using these data measurements, they were able to calculate the temperature at any given distance within the pipe. This was a complicated calculation they had set up in Python and completed using LabVIEW and modules!

All in all, “using the right tool for the right job” are the words to live by. While LabVIEW and Python approach test workflow with unique strengths, it can be the combination of the two that provides the best results.