Tektronix Technical Forums are maintained by community involvement. Feel free to post questions or respond to questions by other members. Should you require a time-sensitive answer, please contact your local Tektronix support center here.

Python 3: Save Hardcopy to PC, PyVISA - MSO/DPO 5K 7K 70K Series Scopes

Programming examples for remote communication with instruments
C/C++, C#, Python, Matlab, LabVIEW
Post Reply
Dave W
Tektronix Applications
Tektronix Applications
Posts: 306
Joined: April 26th, 2010, 12:01 pm
Country: United States

Python 3: Save Hardcopy to PC, PyVISA - MSO/DPO 5K 7K 70K Series Scopes

Post by Dave W » May 23rd, 2016, 4:30 pm

This example demonstrates how to use Python along with PyVISA to save hard copy screen images to the PC from MSO/DPO 5000, 7000 and 70000 Series Scopes.

Code: Select all

#-------------------------------------------------------------------------------
# Name:  Save Hardcopy to PC using PyVisa for MSO/DPO 5K 7K & 70K Series Scopes
# Purpose:  This example demonstrates how to save a hard copy screen image from
#   the scope to the PC.
#
# Created:  2016-05-23
#
# Development Environment: Python 3.4, PyVisa 1.8, NI-VISA 2015, Windows 8.1
#
# Compatible Instruments: MSO/DPO 5000, 7000 & 70000 Series Oscilliscopes
#
# Compatible Interfaces:  USB, Ethernet
#
# Tektronix provides the following example "AS IS" with no support or warranty.
#
#-------------------------------------------------------------------------------

from datetime import datetime # std library
import visa # https://pyvisa.readthedocs.org/en/stable/

# Modify the following lines to configure this script for your instrument
#==============================================
visaResourceAddr = 'MSO5204B'
fileSaveLocation = r'C:\Temp\\' # Folder on your PC where to save image
#==============================================

rm = visa.ResourceManager()
scope = rm.open_resource(visaResourceAddr)

print(scope.query('*IDN?'))

scope.write("HARDCopy:PORT FILE;")
scope.write("EXPort:FORMat PNG")

# Set where the file will be saved on the scope's hard drive.  This is not
# where it will be saved on your PC.
scope.write("HARDCopy:FILEName \"C:\\Temp.png\"")

scope.write("HARDCopy STARt")

# Read the image file from the scope's hard drive
scope.write("FILESystem:READFile \"C:\\Temp.png\"")
imgData = scope.read_raw()

# Generate a filename based on the current Date & Time
dt = datetime.now()
fileName = dt.strftime("%Y%m%d_%H%M%S.png")

# Save the transfered image to the hard drive of your PC
imgFile = open(fileSaveLocation + fileName, "wb")
imgFile.write(imgData)
imgFile.close()

# Delete the image file from the scope's hard drive.
scope.write("FILESystem:DELEte \"C:\\Temp.png\"")

scope.close()
rm.close()

Carl M
Tektronix Applications
Tektronix Applications
Posts: 801
Joined: July 30th, 2008, 4:45 pm
Country: United States

Re: Save Hardcopy to PC, PyVisa - MSO/DPO 5K 7K 70K Series Scopes

Post by Carl M » June 15th, 2016, 11:43 am

my personal preference is to setup the instrument with a mapped network share and save directly to that.
Tektronix Application Engineer

Dave W
Tektronix Applications
Tektronix Applications
Posts: 306
Joined: April 26th, 2010, 12:01 pm
Country: United States

Re: Python 3: Save Hardcopy to PC, PyVISA - MSO/DPO 5K 7K 70K Series Scopes

Post by Dave W » February 27th, 2020, 9:27 am

Note: On scopes running Windows 10 you can no longer save the hardcopy directly to C:\ due to the default permissions settings in Windows. If you try you will likely notice the scope giving a GDI+ error when you send the HARDCOPY START command. The simplest solution is to instead save to C:\Temp\ folder instead. Often this folder already exists, but if not, just use Windows Explorer to create it.

Post Reply

Return to “Remote Instrument Communication (Programming) Examples”

Who is online

Users browsing this forum: No registered users and 5 guests