ARTICLE AD BOX
I believe the best way to simulate pyvisa instruments is with pyvisa-sim and using custom .yaml files.
I referenced the following docs:
https://pyvisa.readthedocs.io/projects/pyvisa-sim/en/latest/index.html
where the secret sauce is:
rm = pyvisa.ResourceManager('your_mock_here.yaml@sim')You can pass the absolute file path to the resource manager followed by @sim and you will use your own custom yaml file for simulation.
The best example .yaml can be found in the source code here:
https://github.com/pyvisa/pyvisa-sim/blob/main/pyvisa_sim/default.yaml
and my initial custom yaml file came out like this:
spec: "1.0" # Device definitions devices: generic: eom: ASRL INSTR: q: "\r\n" r: "\n" dialogues: # Query commands (returning data) - q: "*IDN?" r: "SIM_COMP,ASRL_SIM_DEVICE,SIM0001,1.0" - q: "*OPC?" r: "1" - q: "SYST:ERR?" r: '0,"No error"' - q: "MEASUREMENT?" r: "MEAS1,PHASE" - q: "MEASUREMENT:MEAS1:RESULTS:ALLACQS:MEAN?" r: "1.2345" - q: "PING" r: "PONG" - q: "INDUCE:ERR" r: '1,"ERROR: SIM INDUCED"' # Write-only commands (return nothing) - q: "CONF:VOLT 1" r: "" - q: "CONF:FREQ 10" r: "" # Catch-all WRITE (no ?) # Secret sauce: Ensures that no resopnse is queued # if a write command is not defined above. This is # helpful for instances where write("*SRE 0") occurs # after instrument connection. - q: "^[^?]+$" r: "" # Resource definitions resources: ASRL0::INSTR: device: generic TCPIP::localhost::INSTR: device: genericHere are my environment versions:
Python 3.12.3 Name: PyVISA Version: 1.15.0 Name: PyVISA-sim Version: 0.7.1