forked from tektronix/Programmatic-Control-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsave_hard_copy_example.py
48 lines (38 loc) · 1.52 KB
/
save_hard_copy_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
#-------------------------------------------------------------------------------
# Name: Save Hardcopy to PC using PyVisa for MSO/DPO/MDO 2K 3K 4K 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/MDO 2000, 3000 & 4000 Series Oscilliscopes
#
# Compatible Interfaces: USB, Ethernet, GPIB
#
# 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 = 'MDO3104'
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("SAVe:IMAGe:FILEFormat PNG")
scope.write("SAVe:IMAGe:INKSaver OFF")
scope.write("HARDCopy STARt")
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")
imgFile = open(fileSaveLocation + fileName, "wb")
imgFile.write(imgData)
imgFile.close()
scope.close()
rm.close()