Debian Codegraph @

pymeasure/instruments/agilent/agilentE4980.py

raw
1 #
2 # This file is part of the PyMeasure package.
3 #
4 # Copyright (c) 2013-2024 PyMeasure Developers
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 # THE SOFTWARE.
23 #
24
25
26 from pymeasure.instruments import Instrument, SCPIUnknownMixin
27 from pymeasure.instruments.validators import strict_discrete_set, strict_range
28 from pyvisa.errors import VisaIOError
29
30
31 class AgilentE4980(SCPIUnknownMixin, Instrument):
32 """Represents LCR meter E4980A/AL"""
33
34 ac_voltage = Instrument.control(":VOLT:LEV?", ":VOLT:LEV %g",
35 "AC voltage level, in Volts",
36 validator=strict_range,
37 values=[0, 20])
38
39 ac_current = Instrument.control(":CURR:LEV?", ":CURR:LEV %g",
40 "AC current level, in Amps",
41 validator=strict_range,
42 values=[0, 0.1])
43
44 frequency = Instrument.control(":FREQ:CW?", ":FREQ:CW %g",
45 "AC frequency (range depending on model), in Hertz",
46 validator=strict_range,
47 values=[20, 2e6])
48
49 # FETCH? returns [A,B,state]: impedance returns only A,B
50 impedance = Instrument.measurement(
51 ":FETCH?",
52 "Measured data A and B, according to :attr:`~.AgilentE4980.mode`",
53 get_process=lambda x: x[:2])
54
55 mode = Instrument.control("FUNCtion:IMPedance:TYPE?", "FUNCtion:IMPedance:TYPE %s",
56 """
57 Select quantities to be measured:
58
59 * CPD: Parallel capacitance [F] and dissipation factor [number]
60 * CPQ: Parallel capacitance [F] and quality factor [number]
61 * CPG: Parallel capacitance [F] and parallel conductance [S]
62 * CPRP: Parallel capacitance [F] and parallel resistance [Ohm]
63
64 - CSD: Series capacitance [F] and dissipation factor [number]
65 - CSQ: Series capacitance [F] and quality factor [number]
66 - CSRS: Series capacitance [F] and series resistance [Ohm]
67
68 * LPD: Parallel inductance [H] and dissipation factor [number]
69 * LPQ: Parallel inductance [H] and quality factor [number]
70 * LPG: Parallel inductance [H] and parallel conductance [S]
71 * LPRP: Parallel inductance [H] and parallel resistance [Ohm]
72
73 - LSD: Series inductance [H] and dissipation factor [number]
74 - LSQ: Seriesinductance [H] and quality factor [number]
75 - LSRS: Series inductance [H] and series resistance [Ohm]
76
77 * RX: Resistance [Ohm] and reactance [Ohm]
78 * ZTD: Impedance, magnitude [Ohm] and phase [deg]
79 * ZTR: Impedance, magnitude [Ohm] and phase [rad]
80 * GB: Conductance [S] and susceptance [S]
81 * YTD: Admittance, magnitude [Ohm] and phase [deg]
82 * YTR: Admittance magnitude [Ohm] and phase [rad]
83 """,
84 validator=strict_discrete_set,
85 values=["CPD", "CPQ", "CPG", "CPRP",
86 "CSD", "CSQ", "CSRS",
87 "LPD", "LPQ", "LPG", "LPRP",
88 "LSD", "LSQ", "LSRS",
89 "RX", "ZTD", "ZTR", "GB", "YTD", "YTR", ])
90
91 trigger_source = Instrument.control("TRIG:SOUR?", "TRIG:SOUR %s",
92 """
93 Select trigger source; accept the values:
94 * HOLD: manual
95 * INT: internal
96 * BUS: external bus (GPIB/LAN/USB)
97 * EXT: external connector""",
98 validator=strict_discrete_set,
99 values=["HOLD", "INT", "BUS", "EXT"])
100
101 def __init__(self, adapter, name="Agilent E4980A/AL LCR meter", **kwargs):
102 super().__init__(
103 adapter, name, **kwargs
104 )
105 self.timeout = 30000
106 # format: output ascii
107 self.write("FORM ASC")
108
109 def freq_sweep(self, freq_list, return_freq=False):
110 """
111 Run frequency list sweep using sequential trigger.
112
113 :param freq_list: list of frequencies
114 :param return_freq: if True, returns the frequencies read from the instrument
115
116 Returns values as configured with :attr:`~.AgilentE4980.mode`
117 """
118 # manual, page 299
119 # self.write("*RST;*CLS")
120 self.write("TRIG:SOUR BUS")
121 self.write("DISP:PAGE LIST")
122 self.write("FORM ASC")
123 # trigger in sequential mode
124 self.write("LIST:MODE SEQ")
125 lista_str = ",".join(['%e' % f for f in freq_list])
126 self.write("LIST:FREQ %s" % lista_str)
127 # trigger
128 self.write("INIT:CONT ON")
129 self.write(":TRIG:IMM")
130 # wait for completed measurement
131 # using the Error signal (there should be a better way)
132 while 1:
133 try:
134 measured = self.values(":FETCh:IMPedance:FORMatted?")
135 break
136 except VisaIOError:
137 pass
138 # at the end return to manual trigger
139 self.write(":TRIG:SOUR HOLD")
140 # gets 4-ples of numbers, first two are data A and B
141 a_data = [measured[_] for _ in range(0, 4 * len(freq_list), 4)]
142 b_data = [measured[_] for _ in range(1, 4 * len(freq_list), 4)]
143 if return_freq:
144 read_freqs = self.values("LIST:FREQ?")
145 return a_data, b_data, read_freqs
146 else:
147 return a_data, b_data
148
149 # TODO: maybe refactor as property?
150 def aperture(self, time=None, averages=1):
151 """
152 Set and get aperture.
153
154 :param time: integration time as string: SHORT, MED, LONG (case insensitive);
155 if None, get values
156 :param averages: number of averages, numeric
157 """
158 if time is None:
159 read_values = self.ask(":APER?").split(',')
160 return read_values[0], int(read_values[1])
161 else:
162 if time.upper() in ["SHORT", "MED", "LONG"]:
163 self.write(f":APER {time}, {averages}")
164 else:
165 raise Exception("Time must be a string: SHORT, MED, LONG")