89 lines
3.3 KiB
Python
89 lines
3.3 KiB
Python
import GPIBPrologix
|
|
import bme280
|
|
import smbus2
|
|
from requests import post
|
|
import csv
|
|
import time
|
|
import datetime
|
|
import numpy as np
|
|
from math import sin
|
|
import os
|
|
|
|
## Initialize GPIB adapter
|
|
GPIB = GPIBPrologix.ResourceManager("/dev/ttyACM0")
|
|
# Connect equipment
|
|
inst3 = GPIB.open_resource(16)
|
|
# Initialize BME280 temperature/humidity sensor
|
|
bus = smbus2.SMBus(1)
|
|
calibration_params = bme280.load_calibration_params(bus, 0x76)
|
|
|
|
# Advantest R6581T
|
|
inst3.query("*RST")
|
|
inst3.query(":CONF:VOLT:DC")
|
|
inst3.query(":SENS:VOLT:DC:RANG 10")
|
|
inst3.query(":SENS:VOLT:DC:NPLC 100")
|
|
inst3.query(":SENS:VOLT:DC:DIG MAX")
|
|
inst3.query(":ZERO:AUTO ON")
|
|
|
|
# Measurement functions
|
|
def readValue(instObj):
|
|
value = instObj.query("FETch?")
|
|
return value
|
|
def getEnvironment(instObj, i2cbus):
|
|
value = instObj.sample(i2cbus, 0x76, calibration_params)
|
|
return value
|
|
|
|
## Create proper directory structure
|
|
basePath = os.getcwd() + "/AdvantestShortedMeasurements/"
|
|
if not os.path.exists(basePath+"/data/"):
|
|
os.makedirs(basePath+"/data/")
|
|
|
|
|
|
SweepNPLC = [1,10,100]
|
|
SweepGuard = ['FLO','LOW']
|
|
SweepVoltageRange = [0.1,1,10,100]
|
|
SweepAzero = ['OFF','ON']
|
|
|
|
for azero in SweepAzero:
|
|
inst3.query(":ZERO:AUTO "+azero)
|
|
for NPLC in SweepNPLC:
|
|
inst3.query(":SENS:VOLT:DC:NPLC "+str(NPLC))
|
|
inst3.query(":SENS:VOLT:DC:DIG MAX")
|
|
for Guard in SweepGuard:
|
|
inst3.query(":INP:GUAR "+str(NPLC))
|
|
for VoltageRange in SweepVoltageRange:
|
|
inst3.query(":SENS:VOLT:DC:RANG "+str(VoltageRange))
|
|
inst3.query(":SENS:VOLT:DC:DIG MAX")
|
|
## Create logfile
|
|
logFileName = 'Advantest-R6581T-NoGuardWire-ShieldCan-'+'Guard_'+Guard+'-'+str(NPLC)+'_NPLC-'+str(VoltageRange)+'_VRange-AZ_'+azero+'.csv'
|
|
with open(basePath+"/data/"+logFileName, 'a') as f:
|
|
writer = csv.writer(f)
|
|
writer.writerow(["DateTime","Measured Volts","Env Pressure","Env Temperature", "Env Humidity"])
|
|
print(basePath+"/data/"+logFileName)
|
|
cntr = 0
|
|
d = datetime.datetime.now()
|
|
dlast = datetime.datetime.now()
|
|
## Collect data
|
|
time.sleep(10)
|
|
sweep = range(200)
|
|
for x in sweep:
|
|
cntr = cntr + 1
|
|
try:
|
|
time.sleep((1/50)*NPLC*2.5)
|
|
timebetween = (d-dlast) * (len(sweep)-cntr)
|
|
dlast = d
|
|
print(str(cntr)+'/'+str(len(sweep))+' Estimated Time Left: '+str(timebetween))
|
|
readout = readValue(inst3)
|
|
data = getEnvironment(bme280, bus)
|
|
#Write to file
|
|
d = datetime.datetime.now()
|
|
dx = d - datetime.timedelta(microseconds=d.microsecond)
|
|
fields=[dx.strftime("%d-%m-%y %H:%M:%S"),float(readout),round(data.humidity,2),round(data.temperature,2),round(data.pressure,2)]
|
|
print(fields)
|
|
with open(basePath+"/data/"+logFileName, 'a') as f:
|
|
writer = csv.writer(f)
|
|
writer.writerow(fields)
|
|
except Exception as e:
|
|
time.sleep(3)
|
|
i = i-1
|