PyVISA is a Python package that provides bindings to the "Virtual Instrument Software Architecture" (VISA) library. It enables control of various measurement devices and test equipment (e.g., oscilloscopes, multimeters, power supplies) through different interfaces like GPIB, RS232, USB, and Ethernet. It acts as a frontend to either a vendor-provided VISA shared library (like NI-VISA or Keysight IO Library Suite) or a pure Python implementation like PyVISA-py. The library is actively maintained, with the current version being 1.16.2, and receives regular updates.
pip install -U pyvisaVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the ResourceManager, list available instruments, open a connection to an instrument, query its identification string, and then close the connection. It includes basic error handling and notes for serial configuration. Replace 'YOUR_INSTRUMENT_ADDRESS' with an actual resource string for your device. If no physical VISA backend is found, it automatically uses the PyVISA-py backend if installed.
Replace `pyvisa.instrument("ADDRESS")` with `rm = pyvisa.ResourceManager(); inst = rm.open_resource("ADDRESS")`. Replace `pyvisa.get_instruments_list()` with `rm.list_resources()`. Replace `inst.ask("CMD")` with `inst.query("CMD")`.Install a VISA runtime from a vendor (like National Instruments or Keysight) appropriate for your operating system, or install `pyvisa-py` via `pip install pyvisa-py`.
Ensure that your Python installation (32-bit or 64-bit) matches the bitness of the installed VISA shared library.
Explicitly specify the path to the VISA library when creating the ResourceManager, e.g., `rm = pyvisa.ResourceManager('/path/to/visa.dll')`, or configure it in a `.pyvisarc` file.Consult your instrument's manual for the correct baud rate, `write_termination`, and `read_termination` characters, and set them on the instrument resource object (e.g., `inst.baud_rate = 9600`, `inst.write_termination = '\n'`, `inst.read_termination = '\n'`).
For delays, use the `query_delay` attribute within `query()` or add delays in your application code. Use `write_termination` and `read_termination` attributes for setting termination characters.