Last active
August 8, 2017 14:08
-
-
Save adamgreig/f6f7aa9771178508e990b9416dd74a94 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io | |
import sys | |
import time | |
import socket | |
import struct | |
from PIL import Image | |
if len(sys.argv) != 2: | |
print("Usage: screenshot_dmm.py <filename>") | |
sys.exit(1) | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.connect(("dmm.bench", 5025)) | |
# Set data to PNG | |
s.send(b"HCOP:SDUM:DATA:FORM PNG\r\n") | |
# Now request a screenshot | |
s.send(b"HCOP:SDUM:DATA?\r\n") | |
# Read the first 2 bytes, the definite-length header | |
# Expected format is `#NMMMMXXXXXXXXXXXXX` where | |
# `#` indicates definite-length, N is the number of digits for M, | |
# and MMMM is the number of data bytes, XXXXX are the data bytes. | |
header = s.recv(2) | |
assert header[0] == ord("#"), "Expected SCPI definite-length block header" | |
file_len_len = int(chr(header[1])) | |
file_len = int(s.recv(file_len_len)) | |
print("File size is", file_len, "bytes") | |
# We'll store the read data in this bytearray | |
data = bytearray(file_len) | |
total_received = 0 | |
# Loop reading data from the socket | |
while total_received < file_len: | |
packet = s.recv(file_len) | |
data[total_received:len(packet)] = packet | |
total_received += len(packet) | |
print("Received", total_received, "bytes") | |
time.sleep(0.2) | |
# Use Pillow to write the file out in whatever format the user wants | |
img = Image.open(io.BytesIO(data)) | |
img.save(sys.argv[1]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io | |
import sys | |
import requests | |
from PIL import Image | |
if len(sys.argv) != 2: | |
print("Usage: screenshot_psu.py <filename>") | |
sys.exit(1) | |
# first log in | |
requests.get("http://psu.bench/cgi/login?pass=keysight") | |
# now download screenshot | |
r = requests.get("http://psu.bench/get/screenshot.bmp") | |
# convert to PNG and save | |
img = Image.open(io.BytesIO(r.content)) | |
img.save(sys.argv[1]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io | |
import sys | |
import time | |
import socket | |
import struct | |
from PIL import Image | |
if len(sys.argv) != 3: | |
print("Usage: screenshot.py <IP address> <filename>") | |
sys.exit(1) | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
# Normally we'd connect on 5025 for automated use, avoiding the user shell | |
# prompts. However the Siglent SDG2042X does not listen on 5025 with current | |
# firmware, only 5024, the interactive shell, so use that instead. | |
s.connect((sys.argv[1], 5024)) | |
# We need to eat up all the junk shell prompts etc | |
s.recv(1000) | |
# Now request a screenshot | |
s.send(b"SCDP\r\n") | |
# Read the first 6 bytes, the BMP header | |
header = s.recv(6) | |
# Check it's a BMP header | |
assert header[0:2] == b"BM", "Expected BMP header" | |
# Read the specified file length, which is the number of bytes we have to read | |
file_len = struct.unpack("<I", header[2:])[0] | |
print("File size is", file_len, "bytes") | |
# We'll store the read data in this bytearray | |
data = bytearray(file_len) | |
data[0:6] = header | |
total_received = 6 | |
# Loop reading data from the socket | |
while total_received < file_len: | |
packet = s.recv(file_len) | |
data[total_received:len(packet)] = packet | |
total_received += len(packet) | |
print("Received", total_received, "bytes") | |
time.sleep(0.2) | |
# Use Pillow to write the file out in whatever format the user wants | |
img = Image.open(io.BytesIO(data)) | |
img.save(sys.argv[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment