PyVISA-sim

0.7.1 · active · verified Fri Apr 17

PyVISA-sim is a Python library that provides a simulated backend for PyVISA, allowing users to develop and test instrument control applications without needing physical hardware. It supports common resource types like TCPIP, GPIB, RS232, and USB, mimicking their behavior. The current version is 0.7.1, released on 2024-05-13, and it follows a regular, active release cadence.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize PyVISA with the simulated backend, list available simulated resources, open a default simulated USB instrument, perform basic SCPI write and read operations, and properly close the instrument and resource manager.

import pyvisa

# Create a resource manager that uses the simulated backend
# The '@sim' string tells PyVISA to load pyvisa-sim as the backend
rm = pyvisa.ResourceManager('@sim')

# List available simulated resources (pyvisa-sim comes with some defaults)
print("Available resources:", rm.list_resources())

# Open a simulated instrument resource
# This instrument is defined within pyvisa-sim's default simulation
try:
    instrument = rm.open_resource('USB::0x1000::0x2000::0x3000::INSTR')

    # Basic SCPI commands
    print("Writing '*IDN?'...")
    instrument.write('*IDN?')
    idn = instrument.read()
    print("Read IDN:", idn)

    # Example of a command that changes state (simulation only)
    instrument.write('MEASURE:VOLTAGE:DC?')
    voltage = instrument.read()
    print("Simulated DC Voltage:", voltage)

    # Close the instrument
    instrument.close()
    print("Instrument closed.")

except Exception as e:
    print(f"An error occurred: {e}")
finally:
    # Close the resource manager
    rm.close()
    print("Resource manager closed.")

view raw JSON →