forked from tektronix/Programmatic-Control-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSaveHardcopyPerformance_example.py
65 lines (52 loc) · 2.15 KB
/
SaveHardcopyPerformance_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#-------------------------------------------------------------------------------
# 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.
#
# Development Environment: Python 3.4, PyVisa 1.8, NI-VISA 2015, Windows 8.1
#
# Compatible Instruments: MSO/DPO 5000(B), 7000(C) & 70000(B)(C)(D)(DX)(SX) Series Oscilliscopes
#
# Compatible Interfaces: USB, Ethernet
#
# Changelog:
# 2024-02-22:
# Updated temporary file path for screenshot to be compatible with Windows 10 security settings
#
# 2016-05-23:
# Original Revision
#
# 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 = 'TCPIP::192.168.1.100::inst0:INSTR'
fileSaveLocation = 'C:\\Users\\Public\\Pictures\\' # 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.
tempFilePath = "\"C:\\Users\\Tek_local_admin\\Pictures\\Temp.png\""
scope.write("HARDCopy:FILEName " + tempFilePath)
scope.write("HARDCopy STARt")
# Read the image file from the scope's hard drive
scope.write("FILESystem:READFile " + tempFilePath)
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 " + tempFilePath)
scope.close()
rm.close()