Category:

Hardware Test Software

Last Updated:

November 4, 2024

Duncan Lowder

Overview

In this post, we will cover how we use pyvisa and the pyvisa-py backend to control a Rigol DP832 Power Supply.

What is VISA?

Virtual Instrument Software Architecture (VISA) is a widely used application programming interface (API) in the test and measurement (T&M) industry for communicating with test equipment from a computer. VISA is a standard that has been implemented by most T&M companies including Keysight, National Instruments, Rohde and Schwartz, and Rigol.

The VISA driver encapsulates the Standard Commands for Programmable Instruments (SCPI) commands, which are an ASCII-based set of commands instrument settings and measurement data.

The Rigol DP832 Programmable Power Supply

When we are building a test fixture that requires multiple power rails, we love to use the Rigol DP832 Programmable Power Supply. This power supply has 2 - 30V, 3A channels, a 1 - 5V, 3A channel, and is controllable using USB!

This instrument is controlled using VISA, and the programming guide (contact us if you would like a copy) defines the SCPI commands that can be used to set the various settings of the power supply.

Controlling the Rigol DP832 using Python

To control the Rigol DP832, we use the pyvisa and pyvisa-py packages. PyVISA started as a wrapper for the IVI-VISA library, which required you to install a VISA library on your system (National Instruments, Keysight, etc.). This works most of the time, however, these are proprietary libraries that do not work on all systems. PyVISA-py is a cross-platform, pure Python implementation of a large part of the VISA standard. We've found it to be very easy to use, regardless of the operating system that is being run by the test host.

Use pip to install PyVISA and PyVISA-py. We also recommend using Python 3.6+.

pip install pyvisa
pip install pyvisa-py

To access VISA devices, create a resource manager and then list your sources

>>> import visa

# Create a resource manager using the pyvisa-py backend
>>> rm = visa.ResourceManager('@py')

# Display all instrument resources
>>> print(rm.list_resources())
('ASRL1::INSTR', 'ASRL2::INSTR', 'GPIB0::12::INSTR')

The Rigol DP832 device will look similar to USB0::6833::3601::DP8G223300053::0::INSTR, which can then be used to connect to the instrument.

# Connect to the instrument
>>> inst = rm.open_resource("USB0::6833::3601::DP8G223300053::0::INSTR")

# Send the identify query to the instrument
>>> inst.query("*IDN?")

We now have pyvisa and pyvisa-py installed, and have validated that we can connect to a Rigol DP832 Programmable Power Supply.

You can find the documentation for the pyvisa library here.

Rigol DP832 Python Module

To control the DP832, we will create a module that will provide functions for conveniently controlling the various power rails and returning the voltages and currents currently being output.

Since Rigol has several different types of power supplies that conform to the same SCPI commands, we can create a single class, which can then be inherited and modified for each specific power supply model.

We can then just import this class instead of having to manually create the VISA instrument connection whenever we want to control a Rigol DP832 Power Supply.

# Import the DP832 class from rigol.py
>>> from rigol import DP832

# Initialize connection
>>> dp832 = DP832(dev_name='USB0::6833::3601::DP8G223300053::0::INSTR', backend='@py')

# Identify the device
>>> dp832.identify()

# Set channel 1 to 3.3V, 1A and enable it
>>> dp832.set_channel_settings(1, 3.3, 1)
>>> dp832.set_ouptut_state(1, True)

More from FixturFab