Rohde & Schwarz Instrument Control (RsInstrument)

raw JSON →
1.124.0 verified Fri May 01 auth: no python

RsInstrument is a Python communication module for Rohde & Schwarz instruments using VISA or socket connections. It provides a high-level API for SCPI command control, data transfer, and instrument discovery. Current version is 1.124.0, requiring Python >= 3.10. The library is actively maintained with regular releases.

pip install rsinstrument
error AttributeError: module 'RsInstrument' has no attribute 'RsInstrument'
cause Incorrect import statement; typically `import RsInstrument` then trying to use RsInstrument.RsInstrument
fix
Use from RsInstrument import RsInstrument to import the class.
error VisaIOError: VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.
cause Timeout is too low or the instrument is not responding.
fix
Increase timeout: instr.visa_timeout = 10000 (ms) or check instrument connection.
error TypeError: __init__() got an unexpected keyword argument 'backend'
cause Using an older version of RsInstrument (<1.0) that doesn't accept the 'backend' parameter.
fix
Upgrade to latest version: pip install --upgrade rsinstrument
breaking Version 1.100.0 changed the default VISA backend from 'rs' to 'pyvisa-py'. Existing scripts using the old backend must specify it explicitly.
fix Install pyvisa-py and set RsInstrument(resource, backend='pyvisa-py') or reinstall the legacy 'rs' backend.
gotcha The library is not thread-safe. Do not share an RsInstrument instance across threads without external locking.
fix Use separate instrument instances per thread or implement proper mutex/lock.
gotcha Resource strings must strictly follow VISA Resource Regular Expression pattern. Incorrect strings cause immediate connection failure.
fix Use format like 'TCPIP::192.168.1.1::INSTR' or 'USB::0x0AAD::0x0119::INSTR'. Validate with instr.utilities.check_resource_string()
deprecated The method `instr.io.timeout` setter is deprecated in favor of `instr.visa_timeout`.
fix Use `instr.visa_timeout = 5000` instead of `instr.io.timeout = 5000`.

Initialize an instrument connection and query its identification.

from RsInstrument import RsInstrument
import os

resource_string = os.environ.get('INSTR_RESOURCE', 'TCPIP::192.168.1.1::INSTR')
instr = RsInstrument(resource_string)
print(instr.query('*IDN?'))
instr.close()