Skip to content

Instantly share code, notes, and snippets.

@FrankBuss
Created October 18, 2017 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FrankBuss/33f4a498c4ab07e7a54a5e9e09c1d4fc to your computer and use it in GitHub Desktop.
Save FrankBuss/33f4a498c4ab07e7a54a5e9e09c1d4fc to your computer and use it in GitHub Desktop.
writes a voltage measurement with second timestamp every second
# Python script for voltage logging
import os.path
import sys
import Gpib
import time
# GPIB Address = 24
inst = Gpib.Gpib(0,24, timeout=60)
inst.clear()
inst.write("G8")
print(inst.read())
# VDC
inst.write("F1")
# 20V range
inst.write("R3")
# slow rate
inst.write("S0")
# external trigger by GPIB command "?" for measurment
inst.write("S0")
# logging loop
LogFile= 'fluke.csv'
with open(LogFile, 'w') as MeterLog:
MeterLog.write('Timestamp,Voltage\n')
inst.write("?")
starttime = 0
while True:
# file is closed while waiting, so that it can be loaded from the webserver
with open(LogFile, 'a') as MeterLog:
volt = float(inst.read())
inst.write("?")
t = time.time()
if starttime == 0:
starttime = t
currenttime = starttime
line = "%s,%f" % (t - starttime, volt)
MeterLog.write(line + '\n')
print(line)
currenttime = currenttime + 1
d = currenttime - time.time()
if d > 0:
time.sleep(d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment