-
-
Save mobilinkd/8a07cc124946c87715c6a1458118411e to your computer and use it in GitHub Desktop.
#!/usr/bin/env python | |
import argparse | |
import sys, time | |
import pyvisa as visa | |
from pyvisa.constants import StatusCode | |
from PIL import Image | |
from io import BytesIO | |
def screendump(device, filename): | |
rm = visa.ResourceManager('@py') | |
# Siglent device | |
scope = rm.open_resource('TCPIP::%s' % device) | |
scope.timeout = 1000 # ms | |
scope.read_trermination = None | |
print(scope.query('*IDN?')) | |
scope.write('SCDP') | |
print(scope.last_status) | |
if scope.last_status == StatusCode.success: | |
time.sleep(1) | |
fp = BytesIO() | |
count = 0 | |
try: | |
data = scope.read_raw(20000000) | |
fp.write(data) | |
count = len(data) | |
except: | |
print("timeout") | |
pass | |
print("Read {} bytes.".format(count)) | |
image = Image.open(fp) | |
image.save(filename) | |
scope.close() | |
rm.close() | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser( | |
description='Grab a screenshot from a Siglent LXI device.') | |
parser.add_argument('--output', '-o', dest='filename', required=True, | |
help='the output filename') | |
parser.add_argument('device', metavar='DEVICE', nargs=1, | |
help='the ip address or hostname of the DSO') | |
args = parser.parse_args() | |
screendump(args.device[0], args.filename) | |
Thank you for your upload! Works well after a few changes. Replaced the write to file part with simple f = open(filename, "wb" and such so I didn't have to install additional files.
Also the rm = visa.ResourceManager('@py') caused some weird issues where it coudn't find a package so i removed the '@py' part
Then I also made so the Software would dump all pics in my C:/temp folder with different filenames so they could be recovered and made so it removed files that are more than 1 month old.
I get an error from the n, status = scope.write('SCDP')
line. It says Exception has occurred: TypeError
cannot unpack non-iterable int object
I get an error from the
n, status = scope.write('SCDP')
line. It says Exception has occurred: TypeError
cannot unpack non-iterable int object
I just updated the code to address the API changes to the pyvisa library.
Thank you for your upload! Works well after a few changes. Replaced the write to file part with simple f = open(filename, "wb" and such so I didn't have to install additional files.
Also the rm = visa.ResourceManager('@py') caused some weird issues where it coudn't find a package so i removed the '@py' part
Then I also made so the Software would dump all pics in my C:/temp folder with different filenames so they could be recovered and made so it removed files that are more than 1 month old.
I handle file management in a bash wrapper script. It knows how to construct the path name with the destination directory and put a timestamp on the filename. PIL is used so the screen dumps can be written out in more efficient image formats such as JPEG and PNG.
Thanks !
Worked great on macOS 10.15.7 with Python3. Only added this comment to file so I remember more quickly how to use.
\#to use: In terminal move to this files directory. Paste following and return: python3 screenDump.py --output some_name.png 192.168.1.5 \# you need the filename.png and the current DHCP address. Note that jpg are 34KB vs 2KB and look blobbier
Might need a slight change to work with USB from command line.
I should add that this code will work to dump screenshots from all of my Siglent gear. I use this code (renamed to siglent_scdp.py
) to dump screenshots from the following equipment: SDM3065X, SDG2042X, SSA3021X, and SDS2204X. I have wrapper scripts that look something like this to automatically save and display a screenshot:
#!/bin/sh
DEVICE=sdg2122x
image="${HOME}/Pictures/${DEVICE}-$(/usr/bin/date -Iseconds).png"
/usr/bin/python ${HOME}/bin/siglent_scdp.py -o $image ${DEVICE} 2> /tmp/error
/usr/bin/eog $image
These scripts (one for each device) are mapped to some of the special keys on my Microsoft keyboard. It just takes a single keypress to grab a screenshot.
Updated to write arbitrary image format based on file extension using PIL