-
Notifications
You must be signed in to change notification settings - Fork 0
/
MCC_GPIB_Library.py
100 lines (83 loc) · 2.76 KB
/
MCC_GPIB_Library.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
#
# Measurement Computing GPIB instrument library
#
import time
import Gpib
#******************************************************************************
# HP 34401A DMM
class DMM:
def __init__(self):
self.device = Gpib.Gpib(0, 5)
# first write after reboot fails so add a retry mechanism
self.device.timeout(9) # 100 ms
written = False
while not written:
try:
self.device.write("*CLS")
except:
pass
else:
written = True
self.device.timeout(13)
self.device.write("INP:IMP:AUTO ON")
self.device.write("CONF:VOLT:DC")
return
def __del__(self):
self.device.ibloc()
def read_voltage(self, resolution, range=0):
if resolution == 0:
self.device.write(":MEAS:VOLT:DC? DEF,DEF")
else:
if range == 0:
self.device.write(":MEAS:VOLT:DC? DEF,MIN")
else:
self.device.write(":MEAS:VOLT:DC? MIN,MIN")
result = self.device.read()
value = float(result)
return value
def read_ac_voltage(self, resolution, range=0):
if resolution == 0:
self.device.write(":MEAS:VOLT:AC? DEF,DEF")
else:
if range == 0:
self.device.write(":MEAS:VOLT:AC? DEF,MIN")
else:
self.device.write(":MEAS:VOLT:AC? MIN,MIN")
result = self.device.read()
value = float(result)
return value
def display(self, string):
self.device.write("DISP:TEXT \"{0:s}\"".format(string))
return
#******************************************************************************
# DataPrecision 8200 calbrator
class DP8200:
def __init__(self):
self.device = Gpib.Gpib(0, 20)
# first write after reboot fails so add a retry mechanism
self.device.timeout(9) # 100 ms
written = False
while not written:
try:
self.device.write("L")
except:
pass
else:
written = True
self.device.timeout(13)
return
def __del__(self):
self.device.write("L")
return
def set_voltage(self, voltage):
if abs(voltage) > 100.0:
intval = int(round(voltage*1000, 0))
string = "V3{0:+08d}".format(intval)
elif abs(voltage) > 10.0:
intval = int(round(voltage*10000, 0))
string = "V2{0:+08d}".format(intval)
else:
intval = int(round(voltage*100000, 0))
string = "V1{0:+08d}".format(intval)
self.device.write(string)
return