NATHAN LEFEUVRE
EN (Language)

← Profile

Expertise

Python test benches

Python to control a bench, process its measurements and automate its tests, on its own or alongside LabVIEW.

On my test benches, Python plays a growing part: control, measurement processing and test automation. A Python test bench is a good fit when the client's team already knows the language, or when the bench mainly has to run tests in sequence and make use of their results.

Controlling the instruments

In Python, I control instruments with the PyVISA library and the SCPI language, such as those found on most benches: ITECH power supplies, Keysight and Keithley instruments. Each instrument receives its commands and returns its measurements through the same interface, whether it is connected over USB, Ethernet or GPIB. National Instruments hardware also has its own official Python libraries, such as nidaqmx, and other suppliers, such as Dewesoft or Gantner Instruments, provide a Python interface.

I keep the same rule as with LabVIEW: measurement channels, instrument addresses and limits are described in configuration files, not in the code. The bench can be rewired or fitted with a new instrument without touching the program.

Acquiring and processing measurements

For me, Python is first and foremost the tool for data processing: I use it to post-process measurements, as I used Matlab before, notably on the metrology benches for the ELT mirrors at Safran Reosc and on the Auxitrol Weston sensor test bench. Filtering a signal, computing a moving average, comparing a curve with its template or plotting the results of a test campaign takes a few lines, with well-proven libraries.

Processing is also a way to check the measurement itself: a saturated channel, a disconnected sensor or a drift show up in the data before they distort a conclusion. Checking measurement reliability is part of designing the bench, not a step added at the end.

Automating tests and reports

An automated test always follows the same sequence: prepare the bench, apply the set points, measure, compare each measurement with its limits, then return the bench to a safe state. Written in Python, this sequence is easy to read, can be versioned with Git and can be tested before it reaches the bench.

This is how the electrical test bench for Auxitrol Weston's temperature and pressure sensors is run.

Each result is recorded with the part under test, the bench configuration and the software version. The results are formatted with pandas, then the test report is produced as a PDF from these records, with nothing copied by hand. When the client uses NI TestStand, the sequencer can also call Python scripts directly.

Python and LabVIEW on the same bench

On many benches, Python and LabVIEW work together. LabVIEW keeps the operator interface, real time and the FPGA; Python handles analysis and automation. The first question to settle is simple: which of the two is in charge?

For a bench that runs for a long time, I keep the two programs separate: they exchange messages over the network, with gRPC or ZeroMQ, and if one stops, the other carries on. Experience has taught me that most failures come not from the code but from the Python installation: a frozen environment for each application avoids them. The four ways of making the two languages communicate are covered in the article Python and LabVIEW.

Python or LabVIEW: how to choose

The choice depends less on the language than on the bench and the team that will keep it running:

  • Python on its own: a new bench without a complex operator interface, tests to run in sequence and a team that already programs in Python.
  • LabVIEW: a rich operator interface, real time on NI CompactRIO or FPGA; this is the territory of a LabVIEW test bench.
  • Both together: LabVIEW for the interface and real time, Python for processing and automation.

Either way, the aim is the same: a bench that the client's team will be able to operate and develop further.

Projects

See also: Custom test bench design · all content tagged #python.