Answer
"""
This Python example shows how to create and transfer a screenshot from Spectrum Analyzer to the controller PC.
Tested with:
- FSW Spectrum Analyzer (FW: 4.70 SP1)
- PyVISA 1.11.3
- Python 3.9
Author: R&S Support - MP
Updated on 22.01.2021
Version: v1.3
Technical support ->
Before running, please always check this script for unsuitable setting! This example does not claim to be complete. All information have been
compiled with care. However, errors can’t be ruled out.
"""
import pyvisa
rm = pyvisa.ResourceManager()
instr = rm.open_resource('TCPIP::192.168.0.1::INSTR') # replace by your IP-address
instr.write_termination = '\n'
instr.read_termination = '\n'
instr.timeout = 3000
instr.write('*RST')
instr.query('*OPC?')
instr.write('*CLS')
print('\n' + instr.query('*IDN?'))
instr.write('INIT:CONT OFF')
instr.write('INIT')
instr.query('*OPC?')
# turns on color printing
instr.write('HCOP:DEV:COL ON')
# select file format
# (WMF | GDI | EWMF | BMP | PNG | JPEG | JPG | PDF | SVG | DOC | RTF)
instr.write('HCOP:DEV:LANG PNG')
# set print to file
instr.write("HCOP:DEST 'MMEM'")
filePathInstr = r"c:\temp\hcopy_dev.png"
filePathPc = r"c:\temp\hcopy.png"
# file path on instrument
instr.write(f'MMEM:NAME "{filePathInstr}"')
# create screenshot
instr.write('HCOP:IMM')
# ask for file data from instrument
fileData = bytes(instr.query_binary_values(f'MMEM:DATA? "{filePathInstr}"', datatype='s'))
# save data in file on local hard drive
newFile = open(filePathPc, "wb")
newFile.write(fileData)
newFile.close()
print(instr.query('SYST:ERR?'))
instr.close()