Skip to content

pyscpi

PyPI version

A Python library for communicating with SCPI devices and a helper library for communicating with the Keysight's Smart Bench Essentials educational equipment. The library communicates using multiple backends including PyVisa, USBTMC and socket communication. The library also provides helper functions for reading oscilloscope waveforms and plotting them.

Using PyVisa and Keysight's IOLibrary

you need to install Keysight's IOLibrary and PyVisa.

Using alternative methods including usb and ethernet

You can use USBTMC, a standard for communicating with instruments using USB using generic drivers. This method works both in Windows and WSL2. Alternatively, you can use the standard TCP/IP sockets to communicate with the instrument. However, you need to connect the instrument on the same network as your computer, either using a direct ethernet cable or a switch/router. If you are not using a router, then you may need to set the instrument's IP address manually or use a DHCP server for dynamic IP allocation. Further information can be found in the here.

Getting Started

Installing

You can install the library using pip:

python -m pip install --upgrade pyscpi

connecting to the instrument using PyVisa

import pyvisa as visa

rm = visa.ResourceManager()
inst = rm.open_resource('<resource address>')

print(inst.query('*IDN?'))

connecting to the instrument using USBTMC

from pyscpi import usbtmc

inst =  usbtmc.Instrument(<VendorID>, <ProductID>)

print(inst.query("*IDN?"))

connecting to the instrument using socket (driverless)

from pyscpi import scpi

inst = scpi.Instrument('<IP address>', 5025)

print(inst.query('*IDN?'))

Reading oscilloscope waveform

from pyscpi.keysight import osc
import numpy as np

t, y1 = osc.readSingleChannel(inst, 1)

Plotting oscilloscope waveform

# %matplotlib ipympl
import matplotlib.pyplot as plt

plt.plot(t, y1)
plt.show()

closing the connection

inst.close()

Acknowledgments

Thanks to Keysight Education for providing the Smart Bench Essentials educational equipment.

USBTMC is used for communicating with the instruments using USB.