from datetime import datetime # std library
import time # std library
import visa # https://pyvisa.readthedocs.io/
# Replace string with your instrument's VISA Resource Address
visaRsrcAddr = "MSO66B"
rm = visa.ResourceManager()
scope = rm.open_resource(visaRsrcAddr)
print(scope.query('*IDN?')) # Print instrument id to console window
# Save image to instrument's local disk
scope.write('SAVE:IMAGe \"C:/Temp.png\"')
# Generate a filename based on the current Date & Time
dt = datetime.now()
fileName = dt.strftime("MSO5_%Y%m%d_%H%M%S.png")
# Wait for instrument to finish writing image to disk
scope.query('*OPC?')
# Read image file from instrument
scope.write('FILESystem:READFile \"C:/Temp.png\"')
imgData = scope.read_raw(1024*1024)
# Save image data to local disk
file = open(fileName, "wb")
file.write(imgData)
file.close()
# Image data has been transferred to PC and saved. Delete image file from instrument's hard disk.
scope.write('FILESystem:DELEte \"C:/Temp.png\"')
scope.close()
rm.close()