Free Shipping logo FREE SHIPPING £75+
50 years of Telonic Instruments Ltd logo CELEBRATING 50+ YEARS
Price Match logo PRICE MATCH GUARANTEE

Programming Example: List connected VISA compatible resources using PyVISA

Posted on: December 14th, 2020 by Doug Lovell

PyVISA is a software library that enables Python applications to communicate with resources (typically instruments) connected to a controlling computer using different buses, including: GPIB, RS-232, LAN, and USB.

This example scans and lists the available resources.

It requires PyVISA to be installed (see the PyVISA documentation for more information)

***

#Example that scans a computer for connected instruments that
#are compatible with the VISA communication protocol.
#
#The instrument VISA resource ID for each compatible instrument
#is then listed.
#
#
#Dependencies:
#Python 3.4 32 bit
#PyVisa 1.7
#
#Rev 1: 08302018 JC

import visa

def main():

rm = visa.ResourceManager()
print (rm.list_resources())

if __name__==’__main__’:

main()

*****

Here is the code:

And here is the result of a scan:

Each connected instrument returns a specific formatted string of characters called the VISA Resource ID.

The resource ID format is as follows:

‘Communication/Board Type (USB, GPIB, etc.)::Resource Information (Vendor ID, Product ID, Serial Number, IP address, etc..)::Resource Type’

In the response, each resource is separated by a comma. So, we have three resources listed in this example:

‘USB0::0x0483::0x7540::SPD3XGB4150080::INSTR’ – This is a power supply (SPD3X) connected via USB (USB0)

‘USB0::0xF4EC::0x1301::SVA1XEAX2R0073::INSTR’ – This is a vector network analyzer (SVA1X) connected via USB (USB0)

‘TCPIP0::192.168.55.122::inst0::INSTR’ – This is an instrument connected via LAN using a TCPIP connection at IP address 192.168.55.122