Created
October 31, 2017 22:38
-
-
Save adamgreig/3e54f3b5e8da75f03268e9e0e5014c68 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 sys | |
import time | |
import socket | |
import datetime | |
import numpy as np | |
import matplotlib.pyplot as plt | |
if len(sys.argv) != 4: | |
print("Usage: psudmm.py <Channel> <Max Voltage> <Voltage Step>") | |
sys.exit(1) | |
channel = sys.argv[1] | |
max_voltage = float(sys.argv[2]) | |
voltage_step = float(sys.argv[3]) | |
print("Channel", channel) | |
print("0 to {}V in {}V steps".format(max_voltage, voltage_step)) | |
targets = np.arange(0, max_voltage, voltage_step) | |
psu_readings = np.zeros(targets.size) | |
dmm_readings = np.zeros(targets.size) | |
dmm = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
psu = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
dmm.connect(("dmm.bench", 5025)) | |
psu.connect(("psu.bench", 5025)) | |
dmm.send("SYST:LAB \"PSU {}\"\r\n".format(channel).encode()) | |
if max_voltage < 10: | |
dmm.send(b"CONF:VOLT:DC 10V\r\n") | |
elif max_voltage < 100: | |
dmm.send(b"CONF:VOLT:DC 100V\r\n") | |
else: | |
raise RuntimeError("Don't know how to handle max_voltage={}" | |
.format(max_voltage)) | |
dmm.send(b"SAMP:COUN 5\r\n") | |
psu.send("INST {}\r\n".format(channel).encode()) | |
psu.send(b"CURR 0.1\r\n") | |
psu.send(b"VOLT 0\r\n") | |
psu.send(b"OUTP ON\r\n") | |
time.sleep(0.1) | |
print("Target \tPSU \tDMM") | |
for idx, target in enumerate(targets): | |
psu.send("VOLT {:.3f}\r\n".format(target).encode()) | |
time.sleep(0.5) | |
dmm.send(b"READ?\r\n") | |
readings = [float(x) for x in dmm.recv(1024).decode().split(",")] | |
dmm_readings[idx] = np.mean(readings[1:]) | |
psu.send(b"MEAS:VOLT?\r\n") | |
psu_readings[idx] = float(psu.recv(1024).decode()) | |
print("{:.6f}\t{:.6f}\t{:.6f}" | |
.format(target, psu_readings[idx], dmm_readings[idx])) | |
psu.send(b"OUTP OFF\r\n") | |
dmm.send(b"SYST:BEEP\r\n") | |
supply_err = dmm_readings - targets | |
readback_err = psu_readings - dmm_readings | |
plt.plot(targets, supply_err*1000, 'b-x', label="Supply Error") | |
plt.plot(targets, readback_err*1000, 'g-x', label="Readback Error") | |
plt.ylabel("Error, mV") | |
plt.xlabel("Target, V") | |
plt.legend(loc='lower left') | |
plt.grid() | |
plt.title("E36312A {}".format(channel)) | |
date = datetime.datetime.utcnow().strftime("%Y%d%mT%H%M%SZ") | |
plt.savefig("e36312a_{}_{}.png".format(channel.lower(), date)) | |
np.savez("e36312a_{}_{}.npz".format(channel.lower(), date), | |
targets=targets, psu_readings=psu_readings, dmm_readings=dmm_readings) |
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]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment