-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeithleys.py~
executable file
·239 lines (181 loc) · 6.87 KB
/
Keithleys.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Sub programs for operating some Keithley instruments
author : Eoin O'Farrell
email : phyoec@nus.edu.sg
last edited : July 2013
Classes for:
6430
InitializeInstruments
ScanInstruments
InitializeDataFile
WriteDataFile
CloseDataFile
GraphData
"""
import rpyc
import visa as visa
import VisaSubs as VisaSubs
import string as string
import re as re
from collections import namedtuple
import time
import math
import numpy as np
import threading
import Queue
######################################################
# At the moment each of the instruments we use is a
# seperate class
#####################################################
class k6430:
def __init__(self,address, compliance = 105e-9, median = 0,repetition =1, integration = 1,source = "VOLT",delay = 0.1, trigger = 0):
self.Address = address
self.Visa = VisaSubs.InitializeGPIB(address,0,term_chars = "\\n")
# Other 6430 properties
self.Compliance = compliance
self.Source = source
self.Integration = integration # Defaults to 1
self.Median = median # Defaults to 0 (no medianing)
self.Repetition = repetition # Defaults to 1 (no averaging)
self.Delay = delay # Defaults to 0 (second)
self.Trigger = trigger # Trigger delay (defaults to 0)
self.Output = False
self.Visa.write(":OUTP 0")
self.Data = [0 ,0]
self.Sense = []
######################################
# Initialization i.e. writing a load of SCPI
#######################################
def Initialize(self,SkipCompliance = False,SkipMath = False):
# A bunch of commands to configure the 6430
self.Visa.write("*RST")
time.sleep(.1)
self.Visa.write("".join((":SOUR:FUNC:MODE ",self.Source)))
# Configure the auto zero (reference)
self.Visa.write(":SYST:AZER:STAT ON")
self.Visa.write(":SYST:AZER:CACH:STAT 1")
self.Visa.write(":SYST:AZER:CACH:RES")
# Disable concurrent mode, measure I and V (not R)
self.Visa.write(":SENS:FUNC:CONC 1")
if self.Source == "VOLT":
self.Sense = "CURR"
elif self.Source == "CURR":
self.Sense = "VOLT"
self.Visa.write("".join((":SENS:FUNC:ON ","\"%s\"," % self.Source,"\"%s\"" % self.Sense)))
self.Visa.write("".join((":FORM:ELEM ","%s," % self.Source,"%s" % self.Sense)))
self.Visa.write("".join((":SENS:",self.Sense,":RANG:AUTO 0")))
# Set the complicance
if not SkipCompliance:
self.Visa.write("".join((":SENS:",self.Sense,":RANG 105e-9")))
self.Visa.write("".join((":SENS:",self.Sense,":PROT:LEV %.3e" % self.Compliance)))
# # Set some filters
self.Visa.write("".join((":SENS:",self.Sense,":NPLC %.2f" % self.Integration)))
if not SkipMath:
self.Visa.write(":SENS:AVER:REP:COUN %d" % self.Repetition)
self.Visa.write(":SENS:MED:RANK %d" % self.Median)
self.Visa.write(":SOUR:DEL %.4f" % self.Delay)
self.Visa.write(":TRIG:DEL %.4f" % self.Trigger)
pass
###########################################
# Set the range and compliance
#######################################
def SetRangeCompliance(self, Range = 105, Compliance = 105):
self.Compliance = Compliance
self.Visa.write("".join((":SENS:",self.Sense,":PROT:LEV %.3e" % self.Compliance)))
if Range:
self.Visa.write("".join((":SENS:",self.Sense,":RANG ","%.2e" % Range)))
else:
self.Visa.write("".join((":SENS:",self.Sense,":RANG:AUTO 1")))
pass
##################################################
# Read data
################################################
def ReadData(self):
Reply = self.Visa.ask(":READ?")
self.Data = [float(i) for i in Reply.split(",")[0:2]]
pass
##################################################
# Set source
##################################################
def SetSource(self,Level):
self.Visa.write("".join((":SOUR:",self.Source," %.4e" % Level)))
pass
#################################################
# Switch the output
###############################################
def SwitchOutput(self):
self.Output = not self.Output
self.Visa.write("".join((":OUTP:STAT ","%d" % self.Output)))
pass
#################################################
# Configure a sweep
###############################################
def ConfigureSweep(self,Start,Stop,Step,Soak = 0):
self.Visa.write("".join((":SOUR:",self.Source,":START %.4e" % Start)))
self.Visa.write("".join((":SOUR:",self.Source,":STOP %.4e" % Stop)))
self.Visa.write("".join((":SOUR:",self.Source,":STEP %.4e" % Step)))
Count = int(1+abs(Stop - Start)/Step)
self.Visa.write(":SOUR:SOAK %.4e" % Soak)
self.Visa.write("TRIG:COUN %d" % Count)
pass
###################################################
# Begin sweep, this doesn't work so well, not recommended
#################################################
def RunConfiguredSweep(self):
self.Visa.write(":SOUR:VOLT:MODE SWE")
self.Visa.write(":SOUR:SWE:SPAC LIN")
self.Visa.write(":SOUR:SWE:RANG AUTO")
self.Visa.write(":SOUR:DEL %0.4e" % self.Delay)
self.SwitchOutput()
pass
######################################################
# Manual sweep, this sweep will be run as a separate process
# so it doesn't block the program
##################################################
def RunSweep(self,Start,Stop,Step,Wait,Mode = "linear",**kwargs):
#self.Visa.write("".join((":SOUR:",self.Source,":MODE FIX")))
Targets = [Start, Stop]
for kw in kwargs.keys():
if kw == "mid":
Mid = kwargs[kw]
for i in Mid:
Targets.insert(len(Targets)-1,i)
Voltage = [Start]
for i in range(1,len(Targets)):
Points = int(1+abs(Targets[i]-Targets[i-1])/Step)
if Mode == "linear":
Voltage = np.hstack([Voltage,np.linspace(Targets[i-1],Targets[i],num = Points)[1:Points]])
if Mode == "log":
Voltage = np.hstack([Voltage,np.linspace(Targets[i-1],Targets[i],num = Points)[1:Points]])
# self.Visa.write("".join((":SOUR:",self.Source," %.4e" % Voltage[0])))
return Voltage
###################################################
# Print a description string
################################################
def Description(self):
DescriptionString = "Keithley6430"
for item in vars(self).items():
if item[0] == "Repetition" or item[0] == "Median" or item[0] == "Integration" or item[0] == "Address":
DescriptionString = ", ".join((DescriptionString,"%s = %.3f" % item))
elif item[0] == "Source" or item[0] == "Sense" or item[0] == "Compliance":
DescriptionString = ", ".join((DescriptionString,"%s = %s" % item))
DescriptionString = "".join((DescriptionString,"\n"))
return DescriptionString
############################################
######### Ramp the source to a final value
#########################################
def Ramp(self,Finish):
if self.Output:
self.ReadData()
VStart = self.Data[0]
N = max(100,int(abs(Finish-VStart)/0.1))
VSweep = np.linspace(VStart,Finish,num=N)
if not self.Output:
self.SwitchOutput()
for i in range(len(VSweep)):
self.SetSource(VSweep[i])
time.sleep(0.05)
self.ReadData()
return