Download This Notebook: VirtualInstruments.ipynb

Virtual Instruments

Introduction

Warning

The vi modules depends on PyVISA as well as some additional libraries. Make sure you’ve followed the instructions in the installation tutorial to ensure a working setup.

Additionally, PyVISA can use a number of different backends to communicate with instruments. The installation of these is up to the user, but there are further instructions in the PyVISA documentation By default, PyVISA uses it’s Python VISA implementation, but certain instrument configurations require their manufacturer’s specific VISA library be installed and used to communicate with instruments. For example, the Keysight IO libraries suite has to be used to communicate with their instruments over GPIB.

The virtual instrument module defines a consistent high-level interface for interacting with different types of instruments that can be controlled with SCPI (or other means). Primarily for scikit-rf, this is vector network analyzers (VNAs), but we are actively working on adding support for spectrum analyzers.

For information on specific instruments, consult the vi module’s documentation.

The currently supported instruments are (organized by manufacturer):

Keysight

NanoVNA

Tip

You can help grow scikit-rf by adding support for more instruments! It’s really not that complicated. Check out the vi module documentation to learn how.

Examples

Note

You can download this Jupyter notebook and run it directly on your PC: VirtualInstruments.ipynb

Make sure to comment out any code that is not needed for your instrument.

Connecting to an instrument

[ ]:
from skrf import Frequency
from skrf.vi.vna.keysight import PNA
from skrf.vi.vna.nanovna import NanoVNAv2

# Keysight PNA over ethernet
instr = PNA(address="TCPIP0::10.0.0.5::INSTR")
ch1 = instr.ch1

# NanoVNA V2 over USB
instr = NanoVNAv2("ASRL/dev/ttyACM0::INSTR")  # Linux
instr = NanoVNAv2("ASRL1::INSTR")  # Windows
ch1 = instr  # the NanoVNA does not support channels

print(instr.id)

Changing the frequency settings of an instrument

[ ]:
freq = Frequency(start=1, stop=2, npoints = 101, unit="GHz")  # create frequency object
ch1.frequency = freq  # apply frequency

Creating measurements on the instrument

[ ]:
# not supported on NanoVNA
ch1.create_measurement(name="Temp S11", parameter="S11")
ch1.create_measurement(name="Temp S22", parameter="S22")

Getting a 2-port network and plotting

[ ]:
ntwk = ch1.get_snp_network(ports=(1,2))
ntwk.plot_s_db()

Deleting measurements on the instrument

[ ]:
# not supported on NanoVNA
ch1.delete_measurement(name="Temp S11")
ch1.delete_measurement(name="Temp S22")