Created
October 18, 2017 13:22
-
-
Save FrankBuss/33f4a498c4ab07e7a54a5e9e09c1d4fc to your computer and use it in GitHub Desktop.
writes a voltage measurement with second timestamp every second
This file contains 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
# 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