{"id":10175,"library":"pyvisa-sim","title":"PyVISA-sim","description":"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.","status":"active","version":"0.7.1","language":"en","source_language":"en","source_url":"https://github.com/pyvisa/pyvisa-sim","tags":["visa","simulation","instrumentation","test","measurement"],"install":[{"cmd":"pip install pyvisa-sim","lang":"bash","label":"Install PyVISA-sim"}],"dependencies":[{"reason":"`pyvisa-sim` acts as a backend for `pyvisa` and requires it for functionality.","package":"pyvisa","optional":false}],"imports":[{"note":"Users typically interact with `pyvisa-sim` by specifying the `@sim` backend string to `pyvisa.ResourceManager`, rather than importing symbols directly from `pyvisa_sim`.","symbol":"ResourceManager","correct":"import pyvisa; rm = pyvisa.ResourceManager('@sim')"}],"quickstart":{"code":"import pyvisa\n\n# Create a resource manager that uses the simulated backend\n# The '@sim' string tells PyVISA to load pyvisa-sim as the backend\nrm = pyvisa.ResourceManager('@sim')\n\n# List available simulated resources (pyvisa-sim comes with some defaults)\nprint(\"Available resources:\", rm.list_resources())\n\n# Open a simulated instrument resource\n# This instrument is defined within pyvisa-sim's default simulation\ntry:\n    instrument = rm.open_resource('USB::0x1000::0x2000::0x3000::INSTR')\n\n    # Basic SCPI commands\n    print(\"Writing '*IDN?'...\")\n    instrument.write('*IDN?')\n    idn = instrument.read()\n    print(\"Read IDN:\", idn)\n\n    # Example of a command that changes state (simulation only)\n    instrument.write('MEASURE:VOLTAGE:DC?')\n    voltage = instrument.read()\n    print(\"Simulated DC Voltage:\", voltage)\n\n    # Close the instrument\n    instrument.close()\n    print(\"Instrument closed.\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\nfinally:\n    # Close the resource manager\n    rm.close()\n    print(\"Resource manager closed.\")","lang":"python","description":"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."},"warnings":[{"fix":"Ensure `pyvisa` is installed: `pip install pyvisa`.","message":"`pyvisa-sim` requires `pyvisa` to be installed and used. It's a backend plugin, not a standalone library. Trying to use it without `pyvisa` will lead to errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always initialize your resource manager with `rm = pyvisa.ResourceManager('@sim')`.","message":"To engage the simulation, you MUST explicitly use the `@sim` backend string (e.g., `pyvisa.ResourceManager('@sim')`). If omitted or misspelled, PyVISA will attempt to connect to actual hardware or the default backend, leading to unexpected behavior or connection errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For specific instrument models or complex scenarios, consult the `pyvisa-sim` documentation on how to customize or extend the simulated instrument behavior.","message":"`pyvisa-sim` provides *simulated* responses. While it aims to mimic real instruments, complex or highly specific instrument behaviors may not be perfectly replicated without further configuration (e.g., custom YAML files or programmatic resource registration).","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Check `rm.list_resources()` to see available resources. For custom resources, configure `pyvisa-sim` with a custom YAML file or by registering resources programmatically.","cause":"The specified resource string (e.g., 'USB::0x1000::0x2000::0x3000::INSTR') does not exist in the currently loaded simulation. `pyvisa-sim` provides default resources, but custom ones need to be configured.","error":"pyvisa.errors.VisaIOError: VI_ERROR_RSRC_NFOUND (resource not found)"},{"fix":"Install `pyvisa-sim` using `pip install pyvisa-sim`. Verify the backend string is exactly `'@sim'` when creating the resource manager.","cause":"`pyvisa-sim` is not installed, or the `@sim` backend string is misspelled/missing when initializing `ResourceManager`.","error":"ValueError: No backend available for the given session. Make sure you have the 'pyvisa-sim' package installed and are using the '@sim' backend alias."},{"fix":"`pyvisa-sim` acts as a backend for `pyvisa`. Most user interaction should be via `pyvisa.ResourceManager('@sim')` and standard PyVISA methods, not by importing symbols directly from `pyvisa_sim`.","cause":"Attempting to import or use a class directly from the `pyvisa_sim` module that is not intended for direct user interaction or does not exist.","error":"AttributeError: module 'pyvisa_sim' has no attribute 'SomeClass'"}]}