3

我正在尝试将屏幕截图从 Rhode & Schwarz - FSV 信号分析仪传输到我的 PC。

如何传输二进制块数据,以便将图片从仪器正确保存到我的 PC 上?我的代码如下。一个文件被保存到我的桌面,但我的计算机出现错误并且无法打开,因为该文件的格式不正确。

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()

文件显示在桌面上

尝试在桌面上打开文件时出错

我确认屏幕截图已保存在仪器上。还用另一台仪器验证了 SCPI 语法是正确的。所以它必须是二进制块数据的传输方式。任何意见是极大的赞赏。

4

2 回答 2

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()

这对我有用。

于 2017-03-14T23:33:25.953 回答
1

PyVisa 1.1 版本 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
于 2020-08-24T22:41:42.937 回答