forked from labrad/servers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagilent_34401A_dmm.py
149 lines (123 loc) · 4.93 KB
/
agilent_34401A_dmm.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
# Copyright (C) 2007 Matthew Neeley
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
### BEGIN NODE INFO
[info]
name = Agilent 34401A DMM
version = 1.4
description =
[startup]
cmdline = %PYTHON% %FILE%
timeout = 20
[shutdown]
message = 987654321
timeout = 20
### END NODE INFO
"""
from labrad.server import setting
from labrad.gpib import GPIBManagedServer, GPIBDeviceWrapper
from twisted.internet.defer import inlineCallbacks, returnValue
from labrad.units import V, mV, Ohm, A, mA, Hz
import time
AC_COUPLING = {
True: 'AC',
False: 'DC'
}
AC_SETTLING_TIME = {
3: 1.66,
20: 0.25,
200: 0.025
}
class AgilentDMMServer(GPIBManagedServer):
name = 'Agilent 34401A DMM'
deviceName = ['HEWLETT-PACKARD 34401A', 'Agilent Technologies 34461A']
@setting(10, AC='b{AC}', returns='v[V]')
def voltage(self, c, AC=False):
""" Measures voltage. Defaults to DC voltage, unless AC = True. """
dev = self.selectedDevice(c)
s = 'AC' if AC else 'DC'
ans = yield dev.query('MEAS:VOLT:%s?' % s)
returnValue(float(ans) * V)
@setting(11, AC='b', returns='v[A]')
def current(self, c, AC=False):
""" Measures current. Defaults to DC current, unless AC = True.
"""
dev = self.selectedDevice(c)
s = 'AC' if AC else 'DC'
ans = yield dev.query('MEAS:CURR:%s?' % s)
returnValue(float(ans) * A)
@setting(12, fourWire='b', returns='v[Ohm]')
def resistance(self, c, fourWire=False):
""" Measures resistance. Defaults to 2-wire measurement, unless fourWire = True. """
dev = self.selectedDevice(c)
ans = yield dev.query('MEAS:%s?' % ('FRES' if fourWire else 'RES'))
returnValue(float(ans) * Ohm)
@setting(13, vRange='v[V]', resolution='v[V]')
def configure_voltage(self, c, vRange=10, resolution=0.0001):
""" Sets the DMM to voltage mode, with given range and resolution. """
dev = self.selectedDevice(c)
dev.write("CONF:VOLT:DC %s, %s" % (vRange, resolution))
@setting(14, returns='v[V]')
def read_voltage(self, c):
""" Does a 'READ' instead of 'MEAS'. Device must previously have been
set to voltage mode with configure_voltage. """
dev = self.selectedDevice(c)
ans = yield dev.query("READ?")
returnValue(float(ans) * V)
@setting(15, AC='b', ac_highpass='v[Hz]', cRange='v[A]')
def configure_current(self, c, AC=False, ac_highpass=3*Hz,
cRange='AUTO'):
""" Sets the DMM to current mode, with given range and freq cutoff.
Args:
AC (bool): True: AC; False: DC
ac_highpass (Value[Hz]): High pass cut off frequency, 3 Hz,
20 Hz or 200 Hz are the options.
cRange (Value[A])): Current range for the DMM. It will round up
to the next highest range.
"""
if cRange != 'AUTO':
cRange = cRange['A']
dev = self.selectedDevice(c)
dev.write(':CONFigure:CURRent:{} {}'.format(AC_COUPLING[AC], cRange))
if AC:
dev.write(':CURR:AC:BAND {}'.format(ac_highpass['Hz']))
@setting(16, returns='v[A]')
def read_current(self, c):
""" Does a 'READ' instead of 'MEAS'. Device must previously have been
set to current mode with configure_current. """
dev = self.selectedDevice(c)
meas_time = yield dev.query(':CURR:AC:BAND?')
yield dev.write(':INITiate')
time.sleep(AC_SETTLING_TIME[int(float(meas_time))])
ans = yield dev.query("FETCh?")
returnValue(float(ans) * A)
@setting(17, highpass_cutoff='v[Hz]', returns='v[Hz]')
def ac_highpass(self, c, highpass_cutoff=None):
"""Get or set the highpass cutoff for AC measurements.
Args:
highpass_cutoff (v[Hz]): Highpass cutoff frequency. Note, this
value will be coerced down to to the nearest value
[3, 20, 200] * Hz.
"""
dev = self.selectedDevice(c)
if highpass_cutoff is not None:
yield dev.write(':SENSe:CURRent:AC:BANDwidth {}'
''.format(highpass_cutoff['Hz']))
ans = yield dev.query(':SENSe:CURRent:AC:BANDwidth?')
returnValue(float(ans) * Hz)
__server__ = AgilentDMMServer()
if __name__ == '__main__':
from labrad import util
util.runServer(__server__)