Skip to content

Instantly share code, notes, and snippets.

@Frank-Buss
Created October 5, 2019 03:46
Show Gist options
  • Save Frank-Buss/4ef987e34988bfd97be51b6708725c0b to your computer and use it in GitHub Desktop.
Save Frank-Buss/4ef987e34988bfd97be51b6708725c0b to your computer and use it in GitHub Desktop.
GPIB voltage logging with a Fluke 8842A
#!/usr/bin/python
# reads a voltage each 10 seconds and prints it
# sample output:
#
# instrument FLUKE,8842A,0,V3.0
# start Sat Oct 5 05:36:48 2019
#
# time voltage
# 0 4.191300
# 10 4.190900
# 20 4.190700
# 30 4.190400
# 40 4.172100
# 50 4.161700
# 60 4.154700
#
# the values are separated by tabs, can be saved as CSV and imported in a spreadsheet program
import Gpib
import time
import sys
# define time step in seconds
step = 10
# GPIB Address = 24
inst = Gpib.Gpib(0,24, timeout=60)
inst.clear()
# show instrument name and version
inst.write("G8")
print("instrument\t" + inst.read().strip())
# configure for VDC measurement
inst.write("F1")
# 20V range
inst.write("R3")
# slow rate
inst.write("S0")
# external trigger by GPIB command "?" for measurment
inst.write("T1")
# trigger first measurement
inst.write("?")
# read current time, start measurement loop about 2 seconds later
t0 = time.time() + 2
t0 = int(t0)
start = t0 + 2 * step
# log start time
print("start\t%s\n" % time.ctime(t0 + step))
# measurement loop
print("time\tvoltage")
first = True
while True:
# wait until next time slot
t = time.time()
time.sleep(t0 - t)
# measure exactly each step seconds
t0 = t0 + step
# read measurement and print it with timestamp
volt = float(inst.read().strip())
# trigger next measurement
inst.write("?")
# print it with time in seconds, ignore first measurement
if first:
first = False
else:
print("%i\t%f\t" % (int(t0 - start), volt))
sys.stdout.flush()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment