{"id":5446,"library":"pyvisa-py","title":"PyVISA-py","description":"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.","status":"active","version":"0.8.1","language":"en","source_language":"en","source_url":"https://github.com/pyvisa/pyvisa-py","tags":["instrument control","VISA","test and measurement","SCPI","serial","USB","GPIB","Ethernet"],"install":[{"cmd":"pip install pyvisa-py","lang":"bash","label":"Install core library"}],"dependencies":[{"reason":"PyVISA-py is a backend for PyVISA, which provides the high-level API for instrument control.","package":"pyvisa","optional":false},{"reason":"Required for interfacing with Serial (ASRL) instruments.","package":"PySerial","optional":true},{"reason":"Required for interfacing with USB (USB INSTR/RAW) instruments. Also requires an underlying USB driver library like libusb.","package":"PyUSB","optional":true},{"reason":"Optional for GPIB instruments, specifically on Linux.","package":"linux-gpib","optional":true},{"reason":"Optional for GPIB instruments on Windows and Linux.","package":"gpib-ctypes","optional":true},{"reason":"Optional for discovering VXI-11 devices on all network interfaces. Without it, discovery is limited to the default interface.","package":"psutil","optional":true},{"reason":"Optional for HiSLIP and VICP device discovery, which relies on mDNS.","package":"zeroconf","optional":true},{"reason":"Optional for enabling the Teledyne LeCroy proprietary VICP protocol.","package":"pyvicp","optional":true}],"imports":[{"note":"When using `pyvisa-py`, you must explicitly specify the '@py' backend for ResourceManager. Otherwise, PyVISA will attempt to load a system-installed VISA library (e.g., NI-VISA) by default, which may not be present or desired.","wrong":"import pyvisa\nrm = pyvisa.ResourceManager()","symbol":"ResourceManager","correct":"import pyvisa\nrm = pyvisa.ResourceManager('@py')"}],"quickstart":{"code":"import pyvisa\n\n# Initialize the Resource Manager with the PyVISA-py backend\n# This tells PyVISA to use the pure Python implementation.\nrm = pyvisa.ResourceManager('@py')\n\n# List available resources (instruments)\n# The output will vary based on connected and supported hardware/emulators\nresources = rm.list_resources()\nprint(f\"Available resources: {resources}\")\n\n# Example of opening a (possibly simulated) instrument\n# This line might fail if no such resource exists or is not properly configured\n# For demonstration, we'll try to open a generic ASRL resource if available.\n# Replace 'ASRL1::INSTR' with an actual resource from your 'resources' list.\nif resources:\n    try:\n        # Choose the first resource or a known one, e.g., 'ASRL1::INSTR'\n        # Ensure the chosen resource type has its optional dependencies installed (e.g., PySerial for ASRL)\n        instrument_address = resources[0]\n        # Fallback to a common dummy address if real ones aren't found, for demonstration\n        if not instrument_address.startswith(('ASRL', 'USB', 'TCPIP', 'GPIB')):\n             instrument_address = 'ASRL1::INSTR' # This will likely fail without PySerial/a real ASRL port\n\n        inst = rm.open_resource(instrument_address)\n        print(f\"Successfully opened: {instrument_address}\")\n        \n        # Example: Query instrument identification (standard SCPI command)\n        # This will likely only work if you have a real instrument or a simulator running\n        try:\n            idn = inst.query('*IDN?')\n            print(f\"Instrument IDN: {idn.strip()}\")\n        except pyvisa.errors.VisaIOError as e:\n            print(f\"Could not query *IDN? on {instrument_address}: {e}\")\n        finally:\n            inst.close()\n            print(f\"Closed {instrument_address}\")\n\n    except pyvisa.errors.VisaIOError as e:\n        print(f\"Could not open resource {instrument_address}: {e}\")\n    except IndexError:\n        print(\"No resources found to open.\")\nelse:\n    print(\"No resources found by PyVISA-py backend.\")\n","lang":"python","description":"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."},"warnings":[{"fix":"For VMs, consult the VM manual for proper hardware passthrough/configuration. For Docker (especially with TCP/IP instruments), consider enabling keepalive packets for the VISA session using `inst.set_visa_attribute(pyvisa.constants.ResourceAttribute.tcpip_keepalive, True)` to prevent idle connections from being dropped.","message":"Using PyVISA-py within a Virtual Machine (VM) or Docker container can lead to unexpected timeouts or connectivity issues when accessing hardware-dependent resources like USB or GPIB. VMs might not properly forward hardware responses, and Docker containers might disconnect idle connections.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Install the relevant optional dependencies for the instrument interface you intend to use (e.g., `pip install pyvisa-py pyserial pyusb`). Refer to the PyVISA-py documentation for a full list of dependencies per resource type.","message":"PyVISA-py's ability to communicate with different instrument types (Serial, USB, GPIB) depends on specific optional Python libraries (e.g., PySerial, PyUSB, linux-gpib, gpib-ctypes). If these are not installed, PyVISA-py may only be able to access TCPIP resources.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure `libusb` or a compatible USB driver library is installed. Consult `PyUSB` documentation and your operating system's guides for specific driver installation and permissions setup (e.g., `udev` rules on Linux).","message":"For USB instruments, `PyUSB` (a dependency for PyVISA-py's USB support) requires an underlying USB driver library (e.g., `libusb`). On Unix-like systems, `udev` rules may need to be modified to grant non-root users access to USB devices. On Windows, you might need to uninstall USBTMC-specific drivers and install a generic driver.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Update your code to use `pyvisa.ResourceManager().open_resource()` instead of `pyvisa.instrument()`. Replace `instrument.ask()` with `instrument.query()`. Review PyVISA's migration guide if upgrading from versions older than 1.5.","message":"While not directly in `pyvisa-py`, the underlying `PyVISA` library introduced significant breaking changes in versions 1.5 and 1.6. Key changes include the removal of the direct `pyvisa.instrument()` function in favor of `ResourceManager().open_resource()` and modifications to `ask()`/`query()` methods and event handler arguments.","severity":"breaking","affected_versions":"PyVISA versions 1.5 and 1.6+"},{"fix":"Always check your instrument's manual for the correct baud rate, stop bits, parity, and flow control settings. Explicitly set `instrument.read_termination` and `instrument.write_termination` to match the instrument's requirements (e.g., `\\n`, `\\r`, or an empty string for no termination).","message":"Incorrect `read_termination` or `write_termination` characters, or an incorrect baud rate, are common issues when communicating with serial instruments. The default baud rate is often 9600, but instrument manuals should be consulted.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}