Capture screen shot of Agilent scope using python

1k Views Asked by At

I'm trying to to capture a screenshot of an Agilent scope in python but using read_raw give me an issue “print cancel” can you please help

`import pyvisa as visa
 import sys
 #
 # Example VISA address for a USB         connection:
 VISA_ADDRESS = 'USB0::0x2A8D::0x1797::CN57046145::0::INSTR'
# Define VISA Resource Manager
scope = visa.ResourceManager('C:\\Windows\\System32\\visa32.dll')
scope.read_termination = '\n'
scope.write_termination = '\n' #or = '\r'

print (scope.query('*IDN?\n'))
scope.write('SAVE:IMAG:FILEF PNG')
scope.write(':HARDcopy: STARt')
raw_data = scope.read_raw ()
f= open ('Shot.png' 'wb')
f.write (raw_data)
f.close `
1

There are 1 best solutions below

3
On
import sys
import time
import pyvisa as visa  # PyVISA library

class SCOPE_MSO_S_104A:
    def __init__(self, address):
        self.rm = visa.ResourceManager(r'C:\WINDOWS\system32\visa64.dll')
        self.scope = self.rm.open_resource(address)
        self.scope.timeout = 10000 # 10s
        self.scope.write_termination = '\n'
        self.scope.read_termination = '\n'
        print('MSO S 104A ID string:\n  ', self.scope.query('*IDN?'), flush=True)
        self.scope.query('*RST;*OPC?')
    def getPng(self, file):
        time.sleep(1)
        data = self.scope.query_binary_values(':DISPlay:DATA? PNG,SCReen,1,NORMal', datatype='B', header_fmt='ieee', container=bytes)
        file_id = open(file, 'wb')
        file_id.write(data)
        file_id.close()
    def closeScope(self):
        self.scope.close()

scope = SCOPE_MSO_S_104A('USB0::0x2A8D::0x9050::MY55160105::0::INSTR')
scope.getPng('newPng.png')
from IPython.display import Image
Image('newPng.png')