PyVISA-py

0.8.1 · active · verified Mon Apr 13

PyVISA-py (version 0.8.1) is an active, pure Python implementation of a Virtual Instrument Software Architecture (VISA) library. It functions as a backend for the PyVISA package, enabling control of various measurement devices over interfaces such as Serial, USB, GPIB, and Ethernet, without requiring proprietary vendor-specific VISA installations. It is actively developed, with recent updates and releases.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `ResourceManager` specifically with the `pyvisa-py` backend, list available instrument resources, and attempt to open and query a resource. Note that connecting to and querying a real instrument requires the instrument to be physically connected and the corresponding optional dependencies (e.g., `PySerial` for serial, `PyUSB` for USB) to be installed. Without a connected instrument or emulator, `list_resources()` might return an empty tuple.

import pyvisa

# Initialize the Resource Manager with the PyVISA-py backend
# This tells PyVISA to use the pure Python implementation.
rm = pyvisa.ResourceManager('@py')

# List available resources (instruments)
# The output will vary based on connected and supported hardware/emulators
resources = rm.list_resources()
print(f"Available resources: {resources}")

# Example of opening a (possibly simulated) instrument
# This line might fail if no such resource exists or is not properly configured
# For demonstration, we'll try to open a generic ASRL resource if available.
# Replace 'ASRL1::INSTR' with an actual resource from your 'resources' list.
if resources:
    try:
        # Choose the first resource or a known one, e.g., 'ASRL1::INSTR'
        # Ensure the chosen resource type has its optional dependencies installed (e.g., PySerial for ASRL)
        instrument_address = resources[0]
        # Fallback to a common dummy address if real ones aren't found, for demonstration
        if not instrument_address.startswith(('ASRL', 'USB', 'TCPIP', 'GPIB')):
             instrument_address = 'ASRL1::INSTR' # This will likely fail without PySerial/a real ASRL port

        inst = rm.open_resource(instrument_address)
        print(f"Successfully opened: {instrument_address}")
        
        # Example: Query instrument identification (standard SCPI command)
        # This will likely only work if you have a real instrument or a simulator running
        try:
            idn = inst.query('*IDN?')
            print(f"Instrument IDN: {idn.strip()}")
        except pyvisa.errors.VisaIOError as e:
            print(f"Could not query *IDN? on {instrument_address}: {e}")
        finally:
            inst.close()
            print(f"Closed {instrument_address}")

    except pyvisa.errors.VisaIOError as e:
        print(f"Could not open resource {instrument_address}: {e}")
    except IndexError:
        print("No resources found to open.")
else:
    print("No resources found by PyVISA-py backend.")

view raw JSON →