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 - 5 Series MSO

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

Python 3: Save Hardcopy to PC, PyVisa - 5 Series MSO

Post by Dave W » January 8th, 2018, 11:57 am

This example demonstrates how to use Python 3 along with PyVISA to save hard copy screen images to the PC from 5 Series MSO Oscilloscopes.

Code: Select all

# Name:  Save Screenshot (Hard Copy) to PC for 5 Series MSO Oscilloscopes
# Purpose:  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/

# Replace string with your instrument's VISA Resource Address
visaRsrcAddr = "MSO58"

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

# 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")

# Image data has been transferred to PC and saved. Delete image file from instrument's hard disk.
scope.write('FILESystem:DELEte \"C:/Temp.png\"')


Please note that to run this code without modification on 5 Series MSO scopes running the Windows OS, TekScope will need to be running in Administrator mode. The reason for this is because this code temporarily saves the image at the root of the C: drive and Windows does not let programs write directly to the root of the C: drive unless the program is ran with Administrative privileges. If you do not want to run TekScope as an Administrator, then you will need to change the temporary file path to a directory that does not require Administrator privileges to write to. For example, create a "C:\Temp" folder and then change the temporary file path to "C:/Temp/Temp.png".

Note: The TekScope firmware will accept either forward slashes or back slashes in the file path for commands that require a file path even though the Windows convention uses back slashes. The TekScope firmware handles the translation automatically.

Posts: 1
Joined: August 27th, 2020, 6:09 am
Country: India

Re: Python 3: Save Hardcopy to PC, PyVisa - 5 Series MSO

Post by pradipta » August 27th, 2020, 6:44 am

We are trying to capture 300 type of parameters of each channel and query timing is 0.25 sec. We don't need full waveform data in each query , just need a single value of each parameter for each timestamp. Can you please provide any sample python script for that?

Posts: 1
Joined: June 17th, 2021, 10:31 pm
Country: India

Re: Python 3: Save Hardcopy to PC, PyVisa - 5 Series MSO

Post by sabari_saravanan » June 17th, 2021, 10:39 pm

Hello Dave W,

Why I'm getting timeout error, when I try out to read the raw_data of an oscilloscope?
Hardcopy.PNG (248.28 KiB) Viewed 368 times

Post Reply

Return to “Remote Instrument Communication (Programming) Examples”

Who is online

Users browsing this forum: No registered users and 1 guest