-
Notifications
You must be signed in to change notification settings - Fork 1
/
Ke26XXA.py
159 lines (137 loc) · 5.81 KB
/
Ke26XXA.py
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#Set all channel defaults to be A for simplicity because we're only working with 1 channel
import comtypes.client as cc
from comtypes import COMError
import pyvisa as visa
cc.GetModule('Ke26XXA.dll')
import comtypes.gen.Ke26XXALib as Ke26XXALib
from ctypes import byref, pointer, c_long, c_float, c_int32, cast, c_char_p, c_char
from matplotlib.pyplot import plot,show
from numpy import arange,linspace
import time
class Ke26XXA(object):
name = 'Keithley 26xxA'
def __init__(self):
self.inst = cc.CreateObject('Ke26XXA.Ke26XXA')
def connect(self, visaAddr):
self.inst.Initialize(visaAddr, False, False, '')
# Sets the voltage for a channel. If cvMode is true sets channel automatically to constant voltage mode
def setVoltage(self, v, chan='a',cvMode=True):
if cvMode:
self.setMode( 'cv')
try:
self.inst.Source.Voltage.Level[chan]=v
except COMError:
raise Ke26XXAException(self.checkError()[1])
def getVoltage(self, chan='a'):
try:
res = self.inst.Measurement.Voltage.Measure(chan)
#res = self.inst.Source.Voltage.Level[chan] This is the old statement
except COMError:
raise Ke26XXAException(self.checkError()[1])
return res
# Sets the current for a channel. If ccMode is true sets channel automatically to constant current mode
def setCurrent(self, c, chan='a', ccMode=True):#renamed
if ccMode:
self.setMode( 'cc')
try:
self.inst.Source.Current.Level[chan]=c
except COMError:
raise Ke26XXAException(self.checkError()[1])
def getCurrent(self, chan='a'):
try:
res = self.inst.Measurement.Current.Measure(chan)
except COMError:
raise Ke26XXAException(self.checkError()[1])
return res
def setVoltageAutorange(self, val,chan='a'):
try:
self.inst.Source.Voltage.AutoRangeEnabled[chan] = val
except COMError:
raise Ke26XXAException(self.checkError()[1])
def setCurrentAutorange(self, val,chan='a'):
try:
self.inst.Source.Current.AutoRangeEnabled[chan] = val
except COMError:
raise Ke26XXAException(self.checkError()[1])
def setCurrentMeasurementRange(self, val,chan='a'):
try:
self.inst.Measurement.Current.Range[chan] = val
except COMError:
raise Ke26XXAException(self.checkError()[1])
def setVoltageLimit (self, val,chan='a'):
try:
self.inst.Source.Voltage.Limit[chan] = val
except COMError:
raise Ke26XXAException(self.checkError()[1])
def setCurrentLimit(self, val, chan='a'):
try:
self.inst.Source.Current.Limit[chan] = val
except COMError:
raise Ke26XXAException(self.checkError()[1])
# Sets mode to be constant current ('cc') or constant voltage ('cv')
def setMode(self, mode,chan='a'):
# In COM driver, cc and cv are flipped
modeDict = {'cv':1,\
'cc':0}
try:
self.inst.Source.Function[chan]=modeDict[mode]
except COMError:
raise Ke26XXAException(self.checkError()[1])
except KeyError:
raise Ke26XXAException('Mode must be either constant current (cc) or constant voltage (cv).')
#set the auto zero function of the DAC smua.AUTOZERO_OFF|smua.AUTOZERO_AUTO|smua.AUTOZERO_ONCE
def setAutoZeroMode(self, mode,chan='a'):
# In COM driver, cc and cv are flipped
modeDict = {'off':0,\
'once':1,\
'auto':2}
try:
self.inst.Measurement.AutoZero[chan]=modeDict[mode]
except COMError:
raise Ke26XXAException(self.checkError()[1])
except KeyError:
raise Ke26XXAException('Mode must be either off, once, or auto.')
# Sets the integration time in number of power line cycles. Range 0.001 to 25
def setNPLC(self, val,chan='a'):
try:
self.inst.Measurement.NPLC[chan] = val
except COMError:
raise Ke26XXAException(self.checkError()[1])
def outputenable(self, enable,chan='a'):
try:
self.inst.Source.OutputEnabled[chan] = enable
except COMError:
raise Ke26XXAException(self.checkError()[1])
def checkError(self):
instErr, errMsg = self.inst.Utility.ErrorQuery()
return instErr, errMsg
def queryErrorStatus(self,val,chan='a'):
self.inst.DriverOperation.QueryInstrumentStatus=val
def set_sense_mode(self,sense_mode="remote"):
if sense_mode == "remote":
sense_mode = 1 # 1 or smuX.SENSE_REMOTE: Selects remote sense (4-wire)
elif sense_mode == "local":
sense_mode = 0 # 0 or smuX.SENSE_LOCAL: Selects local sense (2-wire)
else:
sense_mode = 0 # 0 or smuX.SENSE_LOCAL: Selects local sense (2-wire)
self.write("{smuX}.sense = {sense_mode}".format(smuX=self.smu_full_string, sense_mode=sense_mode))
def sweep(self,meas,actstar,actend,steps):#type in V and A, use string(For testing not used)
start=actstar.split(" ")
start=int(start[0])
end=actend.split(" ")
end=int(end[0])
xran=linspace(start,end,steps)
yran=[]
if meas=="V":
for i in range(steps):
self.setCurrent(xran[i])
yran.append(self.getVoltage())
if meas=="C":
for i in range(steps):
self.setVoltage(xran[i])
yran.append(self.getCurrent())
print(xran,yran)
plot(xran,yran)
show()
class Ke26XXAException(Exception):
pass