-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeithley_Class.py
More file actions
70 lines (58 loc) · 1.91 KB
/
Keithley_Class.py
File metadata and controls
70 lines (58 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import pyvisa
import matplotlib.pyplot as plt
import numpy as np
import time
# setup for resource manager and naming the instrument
class Keithley():
def __init__(self, current):
self.keithley = None
self.current = current * 10 ** -6
self.values = None
def connect(self):
rm = pyvisa.ResourceManager()
self.keithley = rm.open_resource("GPIB::1::INSTR")
#IDN = self.keithley.write("*IDN?")
#print(IDN)
self.keithley.write("SOUR:DELT:HIGH " + str(self.current))
# Arms the 6220 in delta mode
self.keithley.write("DELTa:ARM")
self.keithley.write("UNIT OHMS")
#begin sweep
self.keithley.write("INIT:IMM")
time.sleep(3)
def getID(self):
rm = pyvisa.ResourceManager()
self.keithley = rm.open_resource("GPIB::1::INSTR")
IDN = self.keithley.write("*IDN?")
return IDN
def GetSample(self):
self.values = []
samples = 10
for n in range(1, samples):
self.values.append(self.keithley.query_ascii_values('SENS:DATA:FRESh?'))
#print(self.values)
#print(len(self.values))
#self.keithley.write("*RST")
sum = 0
for i in range(len(self.values)):
sum = sum + self.values[i][0]
average = sum / len(self.values)
#print(str(round(average)) + " OHMS")
return average
def PlotResults(self):
x = [x for x, y in self.values]
y = [y for x, y in self.values]
plt.ylabel('Resistance (Ohms)')
plt.xlabel('Time (ms)')
plt.plot(y,x)
plt.show()
def Abort(self):
self.keithley.write("SOUR:SWE:ABOR")
if __name__ == "__main__":
my_instrument = Keithley(2)
print(my_instrument.getID())
my_instrument.connect()
print(my_instrument.GetSample())
time.sleep(5)
print(my_instrument.GetSample())
my_instrument.Abort()