Skip to content
This repository was archived by the owner on Jun 9, 2025. It is now read-only.

Commit 4102ade

Browse files
committed
better
1 parent 5f01725 commit 4102ade

File tree

1 file changed

+70
-100
lines changed

1 file changed

+70
-100
lines changed

pymeasure/instruments/keithley/keithley2600.py

Lines changed: 70 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@
2727
from warnings import warn
2828

2929
import numpy as np
30-
3130
from pymeasure.instruments import Instrument, SCPIUnknownMixin
32-
from pymeasure.instruments.validators import strict_discrete_set, truncated_range
31+
from pymeasure.instruments.validators import truncated_range, strict_discrete_set
3332

3433
# Setup logging
3534
log = logging.getLogger(__name__)
@@ -40,23 +39,27 @@ class Keithley2600(SCPIUnknownMixin, Instrument):
4039
"""Represents the Keithley 2600 series (channel A and B) SourceMeter"""
4140

4241
def __init__(self, adapter, name="Keithley 2600 SourceMeter", **kwargs):
43-
super().__init__(adapter, name, **kwargs)
44-
self.ChA = Channel(self, "a")
45-
self.ChB = Channel(self, "b")
42+
super().__init__(
43+
adapter,
44+
name,
45+
**kwargs
46+
)
47+
self.ChA = Channel(self, 'a')
48+
self.ChB = Channel(self, 'b')
4649

4750
@property
4851
def next_error(self):
49-
"""Returns a tuple of an error code and message from a
50-
single error."""
51-
err = self.ask("print(errorqueue.next())")
52-
err = err.split("\t")
52+
""" Returns a tuple of an error code and message from a
53+
single error. """
54+
err = self.ask('print(errorqueue.next())')
55+
err = err.split('\t')
5356
# Keithley Instruments Inc. sometimes on startup
5457
# if tab delimitated message is greater than one, grab first two as code, message
5558
# otherwise, assign code & message to returned error
5659
if len(err) > 1:
5760
err = (int(float(err[0])), err[1])
5861
code = err[0]
59-
message = err[1].replace('"', "")
62+
message = err[1].replace('"', '')
6063
else:
6164
code = message = err[0]
6265
log.info(f"ERROR {str(code)},{str(message)} - len {str(len(err))}")
@@ -67,36 +70,6 @@ def error(self):
6770
warn("Deprecated to use `error`, use `next_error` instead.", FutureWarning)
6871
return self.next_error
6972

70-
def clear(self):
71-
"""Clears the instrument status byte"""
72-
self.write("status.reset()")
73-
74-
def reset(self):
75-
"""Resets the instrument."""
76-
self.write("*reset()")
77-
78-
@property
79-
def complete(self):
80-
"""This property allows synchronization between a controller and a device. The Operation Complete
81-
query places an ASCII character 1 into the device's Output Queue when all pending
82-
selected device operations have been finished.
83-
"""
84-
return self.ask("waitcomplete() print([[1]])").strip()
85-
86-
@property
87-
def status(self):
88-
"""Requests and returns the status byte and Master Summary Status bit."""
89-
return self.ask("print(tostring(status.condition))").strip()
90-
91-
@property
92-
def id(self):
93-
"""Requests and returns the identification of the instrument."""
94-
return self.ask(
95-
"print([[Keithley Instruments, Model]]..localnode.model..[[,]]..\
96-
localnode.serialno.. [[, ]]..localnode.revision)"
97-
).strip()
98-
99-
10073
class Channel:
10174
def __init__(self, instrument, channel):
10275
self.instrument = instrument
@@ -125,23 +98,21 @@ def check_errors(self):
12598
return self.instrument.check_errors()
12699

127100
source_output = Instrument.control(
128-
"source.output",
129-
"source.output=%d",
101+
'source.output', 'source.output=%d',
130102
"""Property controlling the channel output state (ON of OFF)
131103
""",
132104
validator=strict_discrete_set,
133-
values={"OFF": 0, "ON": 1},
134-
map_values=True,
105+
values={'OFF': 0, 'ON': 1},
106+
map_values=True
135107
)
136108

137109
source_mode = Instrument.control(
138-
"source.func",
139-
"source.func=%d",
110+
'source.func', 'source.func=%d',
140111
"""Property controlling the channel source function (Voltage or Current)
141112
""",
142113
validator=strict_discrete_set,
143-
values={"voltage": 1, "current": 0},
144-
map_values=True,
114+
values={'voltage': 1, 'current': 0},
115+
map_values=True
145116
)
146117

147118
measure_nplc = Instrument.control(
@@ -156,123 +127,121 @@ def check_errors(self):
156127
###############
157128
# Current (A) #
158129
###############
159-
current = Instrument.measurement("measure.i()", """ Reads the current in Amps """)
130+
current = Instrument.measurement(
131+
'measure.i()',
132+
""" Reads the current in Amps """
133+
)
160134

161135
source_current = Instrument.control(
162-
"source.leveli",
163-
"source.leveli=%f",
136+
'source.leveli', 'source.leveli=%f',
164137
""" Property controlling the applied source current """,
165138
validator=truncated_range,
166-
values=[-1.5, 1.5],
139+
values=[-1.5, 1.5]
167140
)
168141

169142
compliance_current = Instrument.control(
170-
"source.limiti",
171-
"source.limiti=%f",
143+
'source.limiti', 'source.limiti=%f',
172144
""" Property controlling the source compliance current """,
173145
validator=truncated_range,
174-
values=[-1.5, 1.5],
146+
values=[-1.5, 1.5]
175147
)
176148

177149
source_current_range = Instrument.control(
178-
"source.rangei",
179-
"source.rangei=%f",
150+
'source.rangei', 'source.rangei=%f',
180151
"""Property controlling the source current range """,
181152
validator=truncated_range,
182-
values=[-1.5, 1.5],
153+
values=[-1.5, 1.5]
183154
)
184155

185156
current_range = Instrument.control(
186-
"measure.rangei",
187-
"measure.rangei=%f",
157+
'measure.rangei', 'measure.rangei=%f',
188158
"""Property controlling the measurement current range """,
189159
validator=truncated_range,
190-
values=[-1.5, 1.5],
160+
values=[-1.5, 1.5]
191161
)
192162

193163
###############
194164
# Voltage (V) #
195165
###############
196-
voltage = Instrument.measurement("measure.v()", """ Reads the voltage in Volts """)
166+
voltage = Instrument.measurement(
167+
'measure.v()',
168+
""" Reads the voltage in Volts """
169+
)
197170

198171
source_voltage = Instrument.control(
199-
"source.levelv",
200-
"source.levelv=%f",
172+
'source.levelv', 'source.levelv=%f',
201173
""" Property controlling the applied source voltage """,
202174
validator=truncated_range,
203-
values=[-200, 200],
175+
values=[-200, 200]
204176
)
205177

206178
compliance_voltage = Instrument.control(
207-
"source.limitv",
208-
"source.limitv=%f",
179+
'source.limitv', 'source.limitv=%f',
209180
""" Property controlling the source compliance voltage """,
210181
validator=truncated_range,
211-
values=[-200, 200],
182+
values=[-200, 200]
212183
)
213184

214185
source_voltage_range = Instrument.control(
215-
"source.rangev",
216-
"source.rangev=%f",
186+
'source.rangev', 'source.rangev=%f',
217187
"""Property controlling the source current range """,
218188
validator=truncated_range,
219-
values=[-200, 200],
189+
values=[-200, 200]
220190
)
221191

222192
voltage_range = Instrument.control(
223-
"measure.rangev",
224-
"measure.rangev=%f",
193+
'measure.rangev', 'measure.rangev=%f',
225194
"""Property controlling the measurement voltage range """,
226195
validator=truncated_range,
227-
values=[-200, 200],
196+
values=[-200, 200]
228197
)
229198

230199
####################
231200
# Resistance (Ohm) #
232201
####################
233202
resistance = Instrument.measurement(
234-
"measure.r()", """ Reads the resistance in Ohms """
203+
'measure.r()',
204+
""" Reads the resistance in Ohms """
235205
)
236206

237207
wires_mode = Instrument.control(
238-
"sense",
239-
"sense=%d",
208+
'sense', 'sense=%d',
240209
"""Property controlling the resistance measurement mode: 4 wires or 2 wires""",
241210
validator=strict_discrete_set,
242-
values={"4": 1, "2": 0},
243-
map_values=True,
211+
values={'4': 1, '2': 0},
212+
map_values=True
244213
)
245214

246215
#######################
247216
# Measurement Methods #
248217
#######################
249218

250219
def measure_voltage(self, nplc=1, voltage=21.0, auto_range=True):
251-
"""Configures the measurement of voltage.
220+
"""C onfigures the measurement of voltage.
252221
:param nplc: Number of power line cycles (NPLC) from 0.001 to 25
253222
:param voltage: Upper limit of voltage in Volts, from -200 V to 200 V
254223
:param auto_range: Enables auto_range if True, else uses the set voltage
255224
"""
256-
log.info(f"{self.channel} is measuring voltage.")
257-
self.write("measure.v()")
258-
self.write(f"measure.nplc={nplc:f}")
225+
log.info("%s is measuring voltage." % self.channel)
226+
self.write('measure.v()')
227+
self.write('measure.nplc=%f' % nplc)
259228
if auto_range:
260-
self.write("measure.autorangev=1")
229+
self.write('measure.autorangev=1')
261230
else:
262231
self.voltage_range = voltage
263232
self.check_errors()
264233

265234
def measure_current(self, nplc=1, current=1.05e-4, auto_range=True):
266-
"""Configures the measurement of current.
235+
""" Configures the measurement of current.
267236
:param nplc: Number of power line cycles (NPLC) from 0.001 to 25
268237
:param current: Upper limit of current in Amps, from -1.5 A to 1.5 A
269238
:param auto_range: Enables auto_range if True, else uses the set current
270239
"""
271-
log.info(f"{self.channel} is measuring current.")
272-
self.write("measure.i()")
273-
self.write(f"measure.nplc={nplc:f}")
240+
log.info("%s is sourcing current." % self.channel)
241+
self.source_mode = 'current'
242+
self.write('measure.nplc=%f' % nplc)
274243
if auto_range:
275-
self.write("measure.autorangei=1")
244+
self.write('measure.autorangei=1')
276245
else:
277246
self.current_range = current
278247
self.check_errors()
@@ -301,8 +270,9 @@ def apply_current(self, current_range=None, compliance_voltage=0.1):
301270
self.compliance_voltage = compliance_voltage
302271
self.check_errors()
303272

304-
def apply_voltage(self, voltage_range=None, compliance_current=0.1):
305-
"""Configures the instrument to apply a source voltage, and
273+
def apply_voltage(self, voltage_range=None,
274+
compliance_current=0.1):
275+
""" Configures the instrument to apply a source voltage, and
306276
uses an auto range unless a voltage range is specified.
307277
The compliance current is also set.
308278
:param compliance_current: A float in the correct range for a
@@ -319,33 +289,33 @@ def apply_voltage(self, voltage_range=None, compliance_current=0.1):
319289
self.check_errors()
320290

321291
def ramp_to_voltage(self, target_voltage, steps=30, pause=0.1):
322-
"""Ramps to a target voltage from the set voltage value over
292+
""" Ramps to a target voltage from the set voltage value over
323293
a certain number of linear steps, each separated by a pause duration.
324294
:param target_voltage: A voltage in Amps
325295
:param steps: An integer number of steps
326-
:param pause: A pause duration in seconds to wait between steps"""
296+
:param pause: A pause duration in seconds to wait between steps """
327297
voltages = np.linspace(self.source_voltage, target_voltage, steps)
328298
for voltage in voltages:
329299
self.source_voltage = voltage
330300
time.sleep(pause)
331301

332302
def ramp_to_current(self, target_current, steps=30, pause=0.1):
333-
"""Ramps to a target current from the set current value over
303+
""" Ramps to a target current from the set current value over
334304
a certain number of linear steps, each separated by a pause duration.
335305
:param target_current: A current in Amps
336306
:param steps: An integer number of steps
337-
:param pause: A pause duration in seconds to wait between steps"""
307+
:param pause: A pause duration in seconds to wait between steps """
338308
currents = np.linspace(self.source_current, target_current, steps)
339309
for current in currents:
340310
self.source_current = current
341311
time.sleep(pause)
342312

343313
def shutdown(self):
344-
"""Ensures that the current or voltage is turned to zero
345-
and disables the output."""
346-
log.info(f"Shutting down channel {self.channel}.")
347-
if self.source_mode == "current":
314+
""" Ensures that the current or voltage is turned to zero
315+
and disables the output. """
316+
log.info("Shutting down channel %s." % self.channel)
317+
if self.source_mode == 'current':
348318
self.ramp_to_current(0.0)
349319
else:
350320
self.ramp_to_voltage(0.0)
351-
self.source_output = "OFF"
321+
self.source_output = 'OFF'

0 commit comments

Comments
 (0)