HW/LaboratoryInstruments/Oscilloscopes/Tektronix/MSO58_500MHz_6p25GS_62p5M/Misc/mso5_screenshot.py

#-----------------------------------------------------------------------------------
#  Save Screenshot (Hard Copy) to PC for 5 Series MSO Oscilloscopes
#
#  This example demonstrates how to save a screen shot (hard copy) image
#  from a 5 Series MSO oscilloscope to the PC.
#
#   Development Environment: Python 3.6, PyVisa 1.8, NI-VISA 2017, Windows 10 x64
#   Compatible Instruments: 5 Series MSO, MSO54, MSO56, MSO58
#   Compatible Interfaces:  USB, Ethernet
#
#   Tektronix provides the following example "AS IS" with no support or warranty.
#-----------------------------------------------------------------------------------
from datetime import datetime 						# std library
import time 								# std library
import visa 								# https://pyvisa.readthedocs.io/
visaRsrcAddr = "TCPIP::192.158.189.XXX::INSTR"
rm = visa.ResourceManager()
scope = rm.open_resource(visaRsrcAddr)
print(scope.query('*IDN?'))  						# Print instrument id to console window
scope.write('SAVE:IMAGe \"C:/Temp.png\"')			        # Save image to instrument's local disk
dt = datetime.now()							# Generate a filename based on the current Date & Time
fileName = dt.strftime("MSO5_%Y%m%d_%H%M%S.png")
scope.query('*OPC?')							# Wait for instrument to finish writing image to disk
scope.write('FILESystem:READFile \"C:/Temp.png\"')	                # Read image file from instrument
imgData = scope.read_raw(1024*1024)
file = open(fileName, "wb")						# Save image data to local disk
file.write(imgData)
file.close()
scope.write('FILESystem:DELEte \"C:/Temp.png\"')	                # Image data has been transferred to PC and saved. Delete image file from instrument's hard disk.
scope.close()
rm.close()