3458A-U180-ToolKit/U180-ToolKit.py
2024-05-05 10:32:09 +02:00

84 lines
3.4 KiB
Python

#import gpibprologix
import os
import json
import time
import csv
import GPIBPrologix
import datetime
GPIB = GPIBPrologix.ResourceManager("/dev/ttyACM0")
instObj = GPIB.open_resource(22)
instObj.write("BEEP")
instObj.write("CAL? 72")
print(instObj.read())
print(instObj.query("CAL? 72"))
time.sleep(60)
## user customisable functions
def readFunc(instObj):
return instObj.read()
def writeFunc(instObj, input):
instObj.write(input)
def queryFunc(instObj, input):
time.sleep(0.1)
return instObj.query(input)
## the main program functionalities, should not be adjusted
def readRunningConfigs():
searchPath = os.path.realpath(os.path.dirname(__file__))+'/RunningConfigs/'
filenames = next(os.walk(searchPath), (None, None, []))[2]
filenames = [item for item in filenames if str.endswith(item,'.json')]
return filenames
def doACAL(dcACAL, ohmACAL, acACAL):
output = queryFunc(instObj, "TEMP?")
if dcACAL == "yes":
writeFunc(instObj, "ACAL DCV")
time.sleep(140+20)
if acACAL == "yes":
writeFunc(instObj, "ACAL ACV")
time.sleep(140+20)
if ohmACAL == "yes":
writeFunc(instObj, "ACAL OHMS")
time.sleep(600+60)
return output
def interrogate3458A(instObj):
output = []
d = datetime.datetime.now()
dx = d - datetime.timedelta(microseconds=d.microsecond)
output.append(dx.strftime("%d-%m-%y %H:%M:%S"))
output.append(queryFunc(instObj,"TEMP?")) # get temperature in device
output.append(queryFunc(instObj,"CAL? 1,1")) # get RREF cal value
output.append(queryFunc(instObj,"CAL? 2,1")) # get VREF cal value
output.append(queryFunc(instObj,"CAL? 78")) # get 10kohm ACAL gain constrant
output.append(queryFunc(instObj,"CAL? 79")) # get 100kohm ACAL gain constrant
output.append(queryFunc(instObj,"CAL? 71")) # get 1v0 ACAL gain constrant
output.append(queryFunc(instObj,"CAL? 70")) # get 0v1 ACAL gain constrant
output.append(queryFunc(instObj,"CAL? 86")) # get 1kohm ACAL ocomp constrant
output.append(queryFunc(instObj,"CAL? 87")) # get 10kohm ACAL ocomp constrant
output.append(queryFunc(instObj,"CAL? 176")) # get acal temperature for ohms
output.append(queryFunc(instObj,"CAL? 59")) # get temperature from during calibration
output.append(queryFunc(instObj,"CAL? 97")) # get 1mamp ACAL gain constrant
output.append(queryFunc(instObj,"CAL? 72")) # get 10v ACAL gain constrant
return output
## main program
# read the config file and do the folder setup
for file in readRunningConfigs():
dataPath = os.path.realpath(os.path.dirname(__file__))+'/RunningConfigs/'+file
with open(dataPath, "r") as read_file:
configData = json.load(read_file)
serialPath = os.path.realpath(os.path.dirname(__file__))+'/data/'+configData['serial']+'/'
if not os.path.exists(serialPath):
os.makedirs(serialPath)
with open(serialPath+configData['serial']+'.csv', 'a') as g:
writer = csv.writer(g)
writer.writerow(["DateTime","TEMP","CAL RREF","CAL VREF","G10K","G100K", "G1V0","G0V1","OCOMP1K","OCOMP10K", "ACALTEMP", "CALTEMP", "G1mA", "G10V"])
doACAL(configData['ACAL-DCV'],configData['ACAL-OHMS'],configData['ACAL-ACV'])
with open(serialPath+configData['serial']+'.csv', 'a') as f:
writer = csv.writer(f)
writer.writerow((interrogate3458A(instObj)))
writeFunc(instObj,"DISP OFF,''")