Automating Tests - Python & PyVISA

Read Time: 
March 2, 2009

Often in testing, it would be nice to have a way of automating mundane tasks on test equipment without having to dig too deep into proprietary code. Well, if your device has a GPIB/Serial/USB interface, you're in luck. Using Python and PyVISA, you can fairly easily automate tasks using only a few lines of code.VISA (Virtual Instrument Software Architecture) is an industry standard implemented by several test and measurement companies to simplify development using their equipment. VISA is maintained by the Interchangeable Virtual Instrument Foundation (IVI Foundation), and provides a common API for controlling test instruments from a computer, while PyVISA provides the necessary hooks between Python and the standard VISA library for ease of programming. After installing Python and the PyVISA package, you can start sending VISA commands in just a few lines of code.An example to call an instrument on a GPIB bus:import visa
test = visa.instrument("GPIB::12")
#Clear settings on equipment
test.write("*CLR")
#Query the identity
test.ask("*IDN?")Writing (when a reply isn't required) is simple using the 'write' method, and if a reply is required, use the 'ask' method. That's it! A simple way to quickly develop/automate testing using your test instruments.

Subscribe to our newsletter
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.