3

I am trying to transfer a screen shot from an Rhode & Schwarz - FSV Signal Analyzer to my PC.

How do I transfer binary block data so that the picture is properly saved onto my PC from the Instrument? My code is below. A file gets saved to my desktop, but my computer throws an error and cannot open because the file is not formatted correctly.

import visa
rm = visa.ResourceManager()
inst = rm.open_resource('TCPIP0::178.168.48.31::inst0::INSTR')

inst.write("mmem:name 'C:\eswScreen.wmf\'")
inst.write("MMEM:DATA? 'C:\eswScreen.wmf\'")
img = inst.read_raw()

target = open(r"C:\Users\myName\Desktop\screenShot.wmf", 'wb')
target.write(img)
target.close()

file shows up on Desktop

Error when trying to open file on Desktop

I verified the screen shot is saved on the instrument. Also verified with another instrument that the SCPI syntax is correct. So it must be how the binblock data is being transferred. Any advice is greatly appreciated.

Hansong Li
  • 417
  • 2
  • 11
  • 26
1funknugget
  • 31
  • 1
  • 4

2 Answers2

2
import pyvisa
rm = pyvisa.ResourceManager()
inst = rm.open_resource('TCPIP0::178.168.48.31::inst0::INSTR')

inst.values_format.is_binary = True
inst.values_format.datatype = 'B'
inst.values_format.is_big_endian = False
inst.values_format.container = bytearray

inst.write("mmem:name 'C:\eswScreen.wmf\'")
img = inst.query_values("MMEM:DATA? 'C:\eswScreen.wmf\'")

target = open(r"C:\Users\user\Desktop\screenShot.wmf", 'wb')
target.write(img)
target.close()

This worked for me.

Hansong Li
  • 417
  • 2
  • 11
  • 26
1

PyVisa 1.1 Version Rohde&Schwarz FSWP

def SaveScreenImage(filepath,filename):
    pna.write('HCOPy:DEVice:LANGuage PNG')
    pna.write(f'MMEMory:NAME "{filepath}\{filename}.png"')
    pna.write('HCOPy:IMMediate')

def ScreenCap(filepath,filename):
    """Capture screen image from anaylzer and save to a file on the host PC

    Example Input:
    
        filepath = 'C:\Data'
        filename = 'test'
    """

    
    SaveScreenImage(r'C:\\',filename)   #create temporary file on analyzer
    img = pna.query_binary_values(f'MMEMory:DATA? "C:\{filename}.png"',datatype='B',is_big_endian=False,container=bytearray)
    
    with open(f'{filepath}\{filename}.png', 'wb') as target:
        target.write(img)
        
    pna.write(f'MMEMory:DELete:IMMediate "C:\{filename}.png"')   #remove file from analyzer
NickB34
  • 11
  • 3