or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

core-backend.mdgpib-communication.mdindex.mdprologix-adapters.mdserial-communication.mdtcpip-communication.mdusb-communication.md
tile.json

tessl/pypi-pyvisa-py

Pure Python implementation of a VISA library for instrument communication.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/pyvisa-py@0.8.x

To install, run

npx @tessl/cli install tessl/pypi-pyvisa-py@0.8.0

index.mddocs/

PyVISA-py

A pure Python implementation of the Virtual Instrument Software Architecture (VISA) library that provides comprehensive backend functionality for PyVISA without requiring proprietary VISA drivers. PyVISA-py enables developers to communicate with test and measurement instruments through multiple interfaces including Serial, USB, GPIB, and Ethernet connections using only Python and cross-platform libraries.

Package Information

  • Package Name: PyVISA-py
  • Language: Python
  • Installation: pip install pyvisa-py
  • Dependencies: pyvisa (≥1.15.0)

Core Imports

import pyvisa_py

Standard usage through PyVISA:

import pyvisa

# Use PyVISA-py as the backend
rm = pyvisa.ResourceManager('@py')

Direct backend access:

from pyvisa_py import PyVisaLibrary

# Create the backend directly
backend = PyVisaLibrary()

Basic Usage

import pyvisa

# Initialize PyVISA with PyVISA-py backend
rm = pyvisa.ResourceManager('@py')

# List available resources
resources = rm.list_resources()
print("Available resources:", resources)

# Open connection to an instrument
# Example resource strings:
# - Serial: "ASRL/dev/ttyUSB0::INSTR" 
# - USB: "USB0::0x1234::0x5678::12345::INSTR"
# - TCP/IP: "TCPIP::192.168.1.100::INSTR"
# - GPIB: "GPIB0::10::INSTR"

try:
    # Open instrument connection
    inst = rm.open_resource("ASRL/dev/ttyUSB0::INSTR")
    
    # Configure communication parameters
    inst.timeout = 2000  # 2 second timeout
    inst.read_termination = '\\n'
    inst.write_termination = '\\n'
    
    # Send commands and read responses
    response = inst.query("*IDN?")
    print("Instrument ID:", response)
    
    # Write commands
    inst.write("*RST")  # Reset instrument
    
    # Read data
    data = inst.read()
    print("Data:", data)
    
finally:
    # Always close connections
    inst.close()
    rm.close()

Architecture

PyVISA-py implements a session-based architecture that dispatches communication operations to specialized session classes:

  • PyVisaLibrary: Main backend that manages sessions and dispatches VISA operations
  • Session Classes: Protocol-specific implementations for different interface types
  • Protocol Layers: Low-level communication protocols (VXI-11, HiSLIP, USBTMC, etc.)
  • Resource Discovery: Automatic enumeration of available instruments per interface type

This design enables PyVISA-py to serve as a drop-in replacement for proprietary VISA implementations while providing the same high-level abstraction and supporting cross-platform deployment.

Capabilities

Core Backend Functionality

The main PyVisaLibrary class that provides the VISA backend implementation with session management, resource operations, and protocol dispatching.

class PyVisaLibrary:
    def open(self, session, resource_name, access_mode=0, open_timeout=0): ...
    def close(self, session): ...
    def read(self, session, count): ...
    def write(self, session, data): ...
    def list_resources(self, session, query="?*::INSTR"): ...
    def get_attribute(self, session, attribute): ...
    def set_attribute(self, session, attribute, attribute_state): ...

Core Backend

Serial Communication

Communication with instruments via serial ports, USB-to-serial adapters, and virtual COM ports with configurable parameters and termination handling.

class SerialSession:
    def __init__(self, resource_manager_session, resource_name, parsed, open_timeout): ...
    def read(self, count): ...
    def write(self, data): ...
    @staticmethod
    def list_resources(): ...

Serial Communication

USB Communication

Direct USB device communication supporting both USBTMC (USB Test & Measurement Class) protocol for instruments and raw USB device access.

class USBInstrSession:
    def __init__(self, resource_manager_session, resource_name, parsed, open_timeout): ...
    def read(self, count): ...
    def write(self, data): ...
    def clear(self): ...
    @staticmethod
    def list_resources(): ...

class USBRawSession:
    def __init__(self, resource_manager_session, resource_name, parsed, open_timeout): ...
    def read(self, count): ...
    def write(self, data): ...

USB Communication

TCP/IP Communication

Network-based instrument communication supporting multiple protocols including VXI-11, HiSLIP, VICP, and raw TCP sockets.

class TCPIPInstrSession:
    def __new__(cls, resource_manager_session, resource_name, parsed, open_timeout): ...
    @staticmethod
    def list_resources(): ...

class TCPIPInstrVxi11:
    def __init__(self, resource_manager_session, resource_name, parsed, open_timeout): ...
    def read(self, count): ...
    def write(self, data): ...

class TCPIPInstrHiSLIP:
    def __init__(self, resource_manager_session, resource_name, parsed, open_timeout): ...
    def read(self, count): ...
    def write(self, data): ...

class TCPIPSocketSession:
    def __init__(self, resource_manager_session, resource_name, parsed, open_timeout): ...
    def read(self, count): ...
    def write(self, data): ...

TCP/IP Communication

GPIB Communication

General Purpose Interface Bus communication for controlling GPIB instruments with support for bus management, addressing, and control operations.

class GPIBSessionDispatch:
    def __new__(cls, resource_manager_session, resource_name, parsed, open_timeout): ...

class GPIBSession:
    def __init__(self, resource_manager_session, resource_name, parsed, open_timeout): ...
    def read(self, count): ...
    def write(self, data): ...
    def gpib_command(self, command_byte): ...
    @staticmethod
    def list_resources(): ...

GPIB Communication

Prologix Adapter Support

Support for Prologix GPIB-USB and GPIB-Ethernet adapters that provide GPIB functionality through USB and TCP/IP interfaces.

class PrologixTCPIPIntfcSession:
    def __init__(self, resource_manager_session, resource_name, parsed, open_timeout): ...
    def read(self, count): ...
    def write(self, data): ...

class PrologixASRLIntfcSession:
    def __init__(self, resource_manager_session, resource_name, parsed, open_timeout): ...
    def read(self, count): ...
    def write(self, data): ...

Prologix Adapters

Resource String Formats

PyVISA-py supports standard VISA resource string formats:

  • Serial: ASRL<port>::INSTR (e.g., ASRL/dev/ttyUSB0::INSTR, ASRLCOM1::INSTR)
  • USB INSTR: USB<board>::<vendor_id>::<product_id>::<serial>::<interface>::INSTR
  • USB RAW: USB<board>::<vendor_id>::<product_id>::<serial>::<interface>::RAW
  • TCP/IP Socket: TCPIP::<hostname>::<port>::SOCKET
  • TCP/IP VXI-11: TCPIP::<hostname>::INSTR
  • TCP/IP HiSLIP: TCPIP::<hostname>::hislip<session>::INSTR
  • VICP: VICP::<hostname>::INSTR
  • GPIB: GPIB<board>::<primary_address>[::secondary_address]::INSTR
  • Prologix TCP/IP: PRLGX-TCPIP::<hostname>::<port>::INTFC
  • Prologix Serial: PRLGX-ASRL::<port>::INTFC

Optional Dependencies

PyVISA-py functionality can be extended with optional packages:

  • pyserial (≥3.0): Serial communication support
  • pyusb: USB device communication
  • gpib-ctypes (≥0.3.0): GPIB communication via ctypes
  • psutil: Enhanced network interface discovery
  • zeroconf: HiSLIP and VICP device discovery
  • pyvicp: VICP protocol support for LeCroy oscilloscopes

Install with specific features:

pip install pyvisa-py[serial,usb,gpib-ctypes]

Error Handling

PyVISA-py provides comprehensive error handling with VISA-compliant status codes:

class OpenError(Exception):
    """Exception raised when failing to open a resource."""
    def __init__(self, error_code=StatusCode.error_resource_not_found): ...

class UnknownAttribute(Exception):
    """Exception raised for unsupported VISA attributes."""
    def __init__(self, attribute): ...

Common error scenarios:

  • Resource not found or unavailable
  • Permission denied for device access
  • Timeout during communication
  • Invalid resource string format
  • Missing optional dependencies for specific interfaces