| 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 |
import time |
| 25 |
import os |
| 26 |
import json |
| 27 |
|
| 28 |
import numpy as np |
| 29 |
import pandas as pd |
| 30 |
|
| 31 |
from pymeasure.instruments import Instrument, SCPIUnknownMixin |
| 32 |
from pymeasure.instruments.validators import (strict_discrete_set, |
| 33 |
truncated_discrete_set, |
| 34 |
strict_range) |
| 35 |
|
| 36 |
import logging |
| 37 |
log = logging.getLogger(__name__) |
| 38 |
log.addHandler(logging.NullHandler()) |
| 39 |
|
| 40 |
###### |
| 41 |
# MAIN |
| 42 |
###### |
| 43 |
|
| 44 |
|
| 45 |
class Agilent4156(SCPIUnknownMixin, Instrument): |
| 46 |
""" Represents the Agilent 4155/4156 Semiconductor Parameter Analyzer |
| 47 |
and provides a high-level interface for taking current-voltage (I-V) measurements. |
| 48 |
|
| 49 |
.. code-block:: python |
| 50 |
|
| 51 |
from pymeasure.instruments.agilent import Agilent4156 |
| 52 |
|
| 53 |
# explicitly define r/w terminations; set sufficiently large timeout or None. |
| 54 |
smu = Agilent4156("GPIB0::25", read_termination = '\\n', write_termination = '\\n', |
| 55 |
timeout=None) |
| 56 |
|
| 57 |
# reset the instrument |
| 58 |
smu.reset() |
| 59 |
|
| 60 |
# define configuration file for instrument and load config |
| 61 |
smu.configure("configuration_file.json") |
| 62 |
|
| 63 |
# save data variables, some or all of which are defined in the json config file. |
| 64 |
smu.save(['VC', 'IC', 'VB', 'IB']) |
| 65 |
|
| 66 |
# take measurements |
| 67 |
status = smu.measure() |
| 68 |
|
| 69 |
# measured data is a pandas dataframe and can be exported to csv. |
| 70 |
data = smu.get_data(path='./t1.csv') |
| 71 |
|
| 72 |
The JSON file is an ascii text configuration file that defines the settings of each channel |
| 73 |
on the instrument. The JSON file is used to configure the instrument using the convenience |
| 74 |
function :meth:`~.Agilent4156.configure` as shown in the example above. For example, the |
| 75 |
instrument setup for a bipolar transistor measurement is shown below. |
| 76 |
|
| 77 |
.. code-block:: json |
| 78 |
|
| 79 |
{ |
| 80 |
"SMU1": { |
| 81 |
"voltage_name" : "VC", |
| 82 |
"current_name" : "IC", |
| 83 |
"channel_function" : "VAR1", |
| 84 |
"channel_mode" : "V", |
| 85 |
"series_resistance" : "0OHM" |
| 86 |
}, |
| 87 |
|
| 88 |
"SMU2": { |
| 89 |
"voltage_name" : "VB", |
| 90 |
"current_name" : "IB", |
| 91 |
"channel_function" : "VAR2", |
| 92 |
"channel_mode" : "I", |
| 93 |
"series_resistance" : "0OHM" |
| 94 |
}, |
| 95 |
|
| 96 |
"SMU3": { |
| 97 |
"voltage_name" : "VE", |
| 98 |
"current_name" : "IE", |
| 99 |
"channel_function" : "CONS", |
| 100 |
"channel_mode" : "V", |
| 101 |
"constant_value" : 0, |
| 102 |
"compliance" : 0.1 |
| 103 |
}, |
| 104 |
|
| 105 |
"SMU4": { |
| 106 |
"voltage_name" : "VS", |
| 107 |
"current_name" : "IS", |
| 108 |
"channel_function" : "CONS", |
| 109 |
"channel_mode" : "V", |
| 110 |
"constant_value" : 0, |
| 111 |
"compliance" : 0.1 |
| 112 |
}, |
| 113 |
|
| 114 |
"VAR1": { |
| 115 |
"start" : 1, |
| 116 |
"stop" : 2, |
| 117 |
"step" : 0.1, |
| 118 |
"spacing" : "LINEAR", |
| 119 |
"compliance" : 0.1 |
| 120 |
}, |
| 121 |
|
| 122 |
"VAR2": { |
| 123 |
"start" : 0, |
| 124 |
"step" : 10e-6, |
| 125 |
"points" : 3, |
| 126 |
"compliance" : 2 |
| 127 |
|
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
""" |
| 132 |
|
| 133 |
def __init__(self, adapter, name="Agilent 4155/4156 Semiconductor Parameter Analyzer", |
| 134 |
**kwargs): |
| 135 |
super().__init__( |
| 136 |
adapter, |
| 137 |
name, |
| 138 |
**kwargs |
| 139 |
) |
| 140 |
|
| 141 |
self.smu1 = SMU(self.adapter, 'SMU1', **kwargs) |
| 142 |
self.smu2 = SMU(self.adapter, 'SMU2', **kwargs) |
| 143 |
self.smu3 = SMU(self.adapter, 'SMU3', **kwargs) |
| 144 |
self.smu4 = SMU(self.adapter, 'SMU4', **kwargs) |
| 145 |
self.vmu1 = VMU(self.adapter, 'VMU1', **kwargs) |
| 146 |
self.vmu2 = VMU(self.adapter, 'VMU2', **kwargs) |
| 147 |
self.vsu1 = VSU(self.adapter, 'VSU1', **kwargs) |
| 148 |
self.vsu2 = VSU(self.adapter, 'VSU2', **kwargs) |
| 149 |
self.var1 = VAR1(self.adapter, **kwargs) |
| 150 |
self.var2 = VAR2(self.adapter, **kwargs) |
| 151 |
self.vard = VARD(self.adapter, **kwargs) |
| 152 |
|
| 153 |
analyzer_mode = Instrument.control( |
| 154 |
":PAGE:CHAN:MODE?", ":PAGE:CHAN:MODE %s", |
| 155 |
""" A string property that controls the instrument operating mode. |
| 156 |
|
| 157 |
- Values: :code:`SWEEP`, :code:`SAMPLING` |
| 158 |
|
| 159 |
.. code-block:: python |
| 160 |
|
| 161 |
smu.analyzer_mode = "SWEEP" |
| 162 |
""", |
| 163 |
validator=strict_discrete_set, |
| 164 |
values={'SWEEP': 'SWE', 'SAMPLING': 'SAMP'}, |
| 165 |
map_values=True, |
| 166 |
check_set_errors=True, |
| 167 |
check_get_errors=True |
| 168 |
) |
| 169 |
|
| 170 |
integration_time = Instrument.control( |
| 171 |
":PAGE:MEAS:MSET:ITIM?", ":PAGE:MEAS:MSET:ITIM %s", |
| 172 |
""" A string property that controls the integration time. |
| 173 |
|
| 174 |
- Values: :code:`SHORT`, :code:`MEDIUM`, :code:`LONG` |
| 175 |
|
| 176 |
.. code-block:: python |
| 177 |
|
| 178 |
instr.integration_time = "MEDIUM" |
| 179 |
""", |
| 180 |
validator=strict_discrete_set, |
| 181 |
values={'SHORT': 'SHOR', 'MEDIUM': 'MED', 'LONG': 'LONG'}, |
| 182 |
map_values=True, |
| 183 |
check_set_errors=True, |
| 184 |
check_get_errors=True |
| 185 |
) |
| 186 |
|
| 187 |
delay_time = Instrument.control( |
| 188 |
":PAGE:MEAS:DEL?", ":PAGE:MEAS:DEL %g", |
| 189 |
""" A floating point property that measurement delay time in seconds, |
| 190 |
which can take the values from 0 to 65s in 0.1s steps. |
| 191 |
|
| 192 |
.. code-block:: python |
| 193 |
|
| 194 |
instr.delay_time = 1 # delay time of 1-sec |
| 195 |
""", |
| 196 |
validator=truncated_discrete_set, |
| 197 |
values=np.arange(0, 65.1, 0.1), |
| 198 |
check_set_errors=True, |
| 199 |
check_get_errors=True |
| 200 |
) |
| 201 |
|
| 202 |
hold_time = Instrument.control( |
| 203 |
":PAGE:MEAS:HTIME?", ":PAGE:MEAS:HTIME %g", |
| 204 |
""" A floating point property that measurement hold time in seconds, |
| 205 |
which can take the values from 0 to 655s in 1s steps. |
| 206 |
|
| 207 |
.. code-block:: python |
| 208 |
|
| 209 |
instr.hold_time = 2 # hold time of 2-secs. |
| 210 |
""", |
| 211 |
validator=truncated_discrete_set, |
| 212 |
values=np.arange(0, 655, 1), |
| 213 |
check_set_errors=True, |
| 214 |
check_get_errors=True |
| 215 |
) |
| 216 |
|
| 217 |
def stop(self): |
| 218 |
"""Stops the ongoing measurement |
| 219 |
|
| 220 |
.. code-block:: python |
| 221 |
|
| 222 |
instr.stop() |
| 223 |
""" |
| 224 |
self.write(":PAGE:SCON:STOP") |
| 225 |
|
| 226 |
def measure(self, period="INF", points=100): |
| 227 |
""" |
| 228 |
Performs a single measurement and waits for completion in sweep mode. |
| 229 |
In sampling mode, the measurement period and number of points can be specified. |
| 230 |
|
| 231 |
:param period: Period of sampling measurement from 6E-6 to 1E11 seconds. |
| 232 |
Default setting is :code:`INF`. |
| 233 |
:param points: Number of samples to be measured, from 1 to 10001. |
| 234 |
Default setting is :code:`100`. |
| 235 |
|
| 236 |
.. code-block::python |
| 237 |
|
| 238 |
instr.measure() #for sweep measurement |
| 239 |
instr.measure(period=100, points=100) #for sampling measurement |
| 240 |
""" |
| 241 |
if self.analyzer_mode == "SWEEP": |
| 242 |
self.write(":PAGE:SCON:MEAS:SING; *OPC?") |
| 243 |
|
| 244 |
else: |
| 245 |
self.write(f":PAGE:MEAS:SAMP:PER {period}") |
| 246 |
self.write(f":PAGE:MEAS:SAMP:POIN {points}") |
| 247 |
self.write(":PAGE:SCON:MEAS:SING; *OPC?") |
| 248 |
|
| 249 |
def disable_all(self): |
| 250 |
""" Disables all channels in the instrument. |
| 251 |
|
| 252 |
.. code-block:: python |
| 253 |
|
| 254 |
instr.disable_all() |
| 255 |
""" |
| 256 |
self.smu1.disable |
| 257 |
time.sleep(0.1) |
| 258 |
self.smu2.disable |
| 259 |
time.sleep(0.1) |
| 260 |
self.smu3.disable |
| 261 |
time.sleep(0.1) |
| 262 |
self.smu4.disable |
| 263 |
time.sleep(0.1) |
| 264 |
self.vmu1.disable |
| 265 |
time.sleep(0.1) |
| 266 |
self.vmu2.disable |
| 267 |
time.sleep(0.1) |
| 268 |
|
| 269 |
def configure(self, config_file): |
| 270 |
""" Configure the channel setup and sweep using a JSON configuration file. |
| 271 |
|
| 272 |
(JSON is the `JavaScript Object Notation`_) |
| 273 |
|
| 274 |
.. _`JavaScript Object Notation`: https://www.json.org/ |
| 275 |
|
| 276 |
:param config_file: JSON file to configure instrument channels. |
| 277 |
|
| 278 |
.. code-block:: python |
| 279 |
|
| 280 |
instr.configure('config.json') |
| 281 |
""" |
| 282 |
self.disable_all() |
| 283 |
obj_dict = {'SMU1': self.smu1, |
| 284 |
'SMU2': self.smu2, |
| 285 |
'SMU3': self.smu3, |
| 286 |
'SMU4': self.smu4, |
| 287 |
'VMU1': self.vmu1, |
| 288 |
'VMU2': self.vmu2, |
| 289 |
'VSU1': self.vsu1, |
| 290 |
'VSU2': self.vsu2, |
| 291 |
'VAR1': self.var1, |
| 292 |
'VAR2': self.var2, |
| 293 |
'VARD': self.vard |
| 294 |
} |
| 295 |
with open(config_file) as stream: |
| 296 |
try: |
| 297 |
instr_settings = json.load(stream) |
| 298 |
except json.JSONDecodeError as e: |
| 299 |
print(e) |
| 300 |
|
| 301 |
# replace dict keys with Instrument objects |
| 302 |
new_settings_dict = {} |
| 303 |
for key, value in instr_settings.items(): |
| 304 |
new_settings_dict[obj_dict[key]] = value |
| 305 |
|
| 306 |
for obj, setup in new_settings_dict.items(): |
| 307 |
for setting, value in setup.items(): |
| 308 |
setattr(obj, setting, value) |
| 309 |
time.sleep(0.1) |
| 310 |
|
| 311 |
def save(self, trace_list): |
| 312 |
""" Save the voltage or current in the instrument display list |
| 313 |
|
| 314 |
:param trace_list: A list of channel variables whose measured data should be saved. |
| 315 |
A maximum of 8 variables are allowed. If only one variable is being saved, a string |
| 316 |
can be specified. |
| 317 |
|
| 318 |
.. code-block:: python |
| 319 |
|
| 320 |
instr.save(['IC', 'IB', 'VC', 'VB']) #for list of variables |
| 321 |
instr.save('IC') #for single variable |
| 322 |
""" |
| 323 |
self.write(":PAGE:DISP:MODE LIST") |
| 324 |
if isinstance(trace_list, list): |
| 325 |
if len(trace_list) > 8: |
| 326 |
raise RuntimeError('Maximum of 8 variables allowed') |
| 327 |
else: |
| 328 |
for name in trace_list: |
| 329 |
self.write(f":PAGE:DISP:LIST \'{name}\'") |
| 330 |
elif isinstance(trace_list, str): |
| 331 |
self.write(f":PAGE:DISP:LIST \'{trace_list}\'") |
| 332 |
else: |
| 333 |
raise TypeError( |
| 334 |
'Must be a string if only one variable is saved, or else a list if' |
| 335 |
'multiple variables are being saved.' |
| 336 |
) |
| 337 |
|
| 338 |
def save_var(self, trace_list): |
| 339 |
""" Save the voltage or current in the instrument variable list. |
| 340 |
|
| 341 |
This is useful if one or two more variables need to be saved in addition to the 8 |
| 342 |
variables allowed by :meth:`~.Agilent4156.save`. |
| 343 |
|
| 344 |
:param trace_list: A list of channel variables whose measured data should be saved. |
| 345 |
A maximum of 2 variables are allowed. If only one variable is being saved, a string |
| 346 |
can be specified. |
| 347 |
|
| 348 |
.. code-block:: python |
| 349 |
|
| 350 |
instr.save_var(['VA', 'VB']) |
| 351 |
""" |
| 352 |
self.write(":PAGE:DISP:MODE LIST") |
| 353 |
if isinstance(trace_list, list): |
| 354 |
if len(trace_list) > 2: |
| 355 |
raise RuntimeError('Maximum of 2 variables allowed') |
| 356 |
else: |
| 357 |
for name in trace_list: |
| 358 |
self.write(f":PAGE:DISP:DVAR \'{name}\'") |
| 359 |
elif isinstance(trace_list, str): |
| 360 |
self.write(f":PAGE:DISP:DVAR \'{trace_list}\'") |
| 361 |
else: |
| 362 |
raise TypeError( |
| 363 |
'Must be a string if only one variable is saved, or else a list if' |
| 364 |
'multiple variables are being saved.' |
| 365 |
) |
| 366 |
|
| 367 |
@property |
| 368 |
def data_variables(self): |
| 369 |
""" |
| 370 |
Get a string list of data variables for which measured data is available. |
| 371 |
|
| 372 |
This looks for all the variables saved by the :meth:`~.Agilent4156.save` and |
| 373 |
:meth:`~.Agilent4156.save_var` methods and returns it. This is useful for creation |
| 374 |
of dataframe headers. |
| 375 |
|
| 376 |
:returns: List |
| 377 |
|
| 378 |
.. code-block:: python |
| 379 |
|
| 380 |
header = instr.data_variables |
| 381 |
""" |
| 382 |
dlist = self.ask(":PAGE:DISP:LIST?").split(',') |
| 383 |
dvar = self.ask(":PAGE:DISP:DVAR?").split(',') |
| 384 |
varlist = dlist + dvar |
| 385 |
return list(filter(None, varlist)) |
| 386 |
|
| 387 |
def get_data(self, path=None): |
| 388 |
""" |
| 389 |
Get the measurement data from the instrument after completion. |
| 390 |
|
| 391 |
If the measurement period is set to :code:`INF` in the :meth:`~.Agilent4156.measure` |
| 392 |
method, then the measurement must be stopped using :meth:`~.Agilent4156.stop` before |
| 393 |
getting valid data. |
| 394 |
|
| 395 |
:param path: Path for optional data export to CSV. |
| 396 |
:returns: Pandas Dataframe |
| 397 |
|
| 398 |
.. code-block:: python |
| 399 |
|
| 400 |
df = instr.get_data(path='./datafolder/data1.csv') |
| 401 |
""" |
| 402 |
if int(self.ask('*OPC?')): |
| 403 |
header = self.data_variables |
| 404 |
self.write(":FORM:DATA ASC") |
| 405 |
# recursively get data for each variable |
| 406 |
for i, listvar in enumerate(header): |
| 407 |
data = self.values(f":DATA? \'{listvar}\'") |
| 408 |
time.sleep(0.01) |
| 409 |
if i == 0: |
| 410 |
lastdata = data |
| 411 |
else: |
| 412 |
data = np.column_stack((lastdata, data)) |
| 413 |
lastdata = data |
| 414 |
|
| 415 |
df = pd.DataFrame(data=data, columns=header, index=None) |
| 416 |
if path is not None: |
| 417 |
_, ext = os.path.splitext(path) |
| 418 |
if ext != ".csv": |
| 419 |
path = path + ".csv" |
| 420 |
df.to_csv(path, index=False) |
| 421 |
|
| 422 |
return df |
| 423 |
|
| 424 |
########## |
| 425 |
# CHANNELS |
| 426 |
########## |
| 427 |
|
| 428 |
|
| 429 |
class SMU(SCPIUnknownMixin, Instrument): |
| 430 |
def __init__(self, adapter, channel, **kwargs): |
| 431 |
super().__init__( |
| 432 |
adapter, |
| 433 |
"SMU of Agilent 4155/4156 Semiconductor Parameter Analyzer", |
| 434 |
**kwargs |
| 435 |
) |
| 436 |
self.channel = channel.upper() |
| 437 |
|
| 438 |
@property |
| 439 |
def channel_mode(self): |
| 440 |
""" A string property that controls the SMU<n> channel mode. |
| 441 |
|
| 442 |
- Values: :code:`V`, :code:`I` or :code:`COMM` |
| 443 |
|
| 444 |
VPULSE AND IPULSE are not yet supported. |
| 445 |
|
| 446 |
.. code-block:: python |
| 447 |
|
| 448 |
instr.smu1.channel_mode = "V" |
| 449 |
""" |
| 450 |
value = self.ask(f":PAGE:CHAN:{self.channel}:MODE?") |
| 451 |
self.check_errors() |
| 452 |
return value |
| 453 |
|
| 454 |
@channel_mode.setter |
| 455 |
def channel_mode(self, mode): |
| 456 |
validator = strict_discrete_set |
| 457 |
values = ["V", "I", "COMM"] |
| 458 |
value = validator(mode, values) |
| 459 |
self.write(f":PAGE:CHAN:{self.channel}:MODE {value}") |
| 460 |
self.check_errors() |
| 461 |
|
| 462 |
@property |
| 463 |
def channel_function(self): |
| 464 |
""" A string property that controls the SMU<n> channel function. |
| 465 |
|
| 466 |
- Values: :code:`VAR1`, :code:`VAR2`, :code:`VARD` or :code:`CONS`. |
| 467 |
|
| 468 |
.. code-block:: python |
| 469 |
|
| 470 |
instr.smu1.channel_function = "VAR1" |
| 471 |
""" |
| 472 |
value = self.ask(f":PAGE:CHAN:{self.channel}:FUNC?") |
| 473 |
self.check_errors() |
| 474 |
return value |
| 475 |
|
| 476 |
@channel_function.setter |
| 477 |
def channel_function(self, function): |
| 478 |
validator = strict_discrete_set |
| 479 |
values = ["VAR1", "VAR2", "VARD", "CONS"] |
| 480 |
value = validator(function, values) |
| 481 |
self.write(f":PAGE:CHAN:{self.channel}:FUNC {value}") |
| 482 |
self.check_errors() |
| 483 |
|
| 484 |
@property |
| 485 |
def series_resistance(self): |
| 486 |
""" Controls the series resistance of SMU<n>. |
| 487 |
|
| 488 |
- Values: :code:`0OHM`, :code:`10KOHM`, :code:`100KOHM`, or :code:`1MOHM` |
| 489 |
|
| 490 |
.. code-block:: python |
| 491 |
|
| 492 |
instr.smu1.series_resistance = "10KOHM" |
| 493 |
|
| 494 |
""" |
| 495 |
value = self.ask(f":PAGE:CHAN:{self.channel}:SRES?") |
| 496 |
self.check_errors() |
| 497 |
return value |
| 498 |
|
| 499 |
@series_resistance.setter |
| 500 |
def series_resistance(self, sres): |
| 501 |
validator = strict_discrete_set |
| 502 |
values = ["0OHM", "10KOHM", "100KOHM", "1MOHM"] |
| 503 |
value = validator(sres, values) |
| 504 |
self.write(f":PAGE:CHAN:{self.channel}:SRES {value}") |
| 505 |
self.check_errors() |
| 506 |
|
| 507 |
@property |
| 508 |
def disable(self): |
| 509 |
""" Deletes the settings of SMU<n>. |
| 510 |
|
| 511 |
.. code-block:: python |
| 512 |
|
| 513 |
instr.smu1.disable() |
| 514 |
""" |
| 515 |
self.write(f":PAGE:CHAN:{self.channel}:DIS") |
| 516 |
self.check_errors() |
| 517 |
|
| 518 |
@property |
| 519 |
def constant_value(self): |
| 520 |
""" Set the constant source value of SMU<n>. |
| 521 |
|
| 522 |
You use this command only if :meth:`~.SMU.channel_function` |
| 523 |
is :code:`CONS` and also :meth:`~.SMU.channel_mode` should not be :code:`COMM`. |
| 524 |
|
| 525 |
:param const_value: Voltage in (-200V, 200V) and current in (-1A, 1A). Voltage or current |
| 526 |
depends on if :meth:`~.SMU.channel_mode` is set to :code:`V` or :code:`I`. |
| 527 |
|
| 528 |
.. code-block:: python |
| 529 |
|
| 530 |
instr.smu1.constant_value = 1 |
| 531 |
|
| 532 |
""" |
| 533 |
if Agilent4156.analyzer_mode.fget(self) == "SWEEP": |
| 534 |
value = self.ask(f":PAGE:MEAS:CONS:{self.channel}?") |
| 535 |
else: |
| 536 |
value = self.ask(f":PAGE:MEAS:SAMP:CONS:{self.channel}?") |
| 537 |
self.check_errors() |
| 538 |
return value |
| 539 |
|
| 540 |
@constant_value.setter |
| 541 |
def constant_value(self, const_value): |
| 542 |
validator = strict_range |
| 543 |
values = self.__validate_cons() |
| 544 |
value = validator(const_value, values) |
| 545 |
if Agilent4156.analyzer_mode.fget(self) == 'SWEEP': |
| 546 |
self.write(f":PAGE:MEAS:CONS:{self.channel} {value}") |
| 547 |
else: |
| 548 |
self.write(":PAGE:MEAS:SAMP:CONS:{} {}".format( |
| 549 |
self.channel, value)) |
| 550 |
self.check_errors() |
| 551 |
|
| 552 |
@property |
| 553 |
def compliance(self): |
| 554 |
""" Sets the *constant* compliance value of SMU<n>. |
| 555 |
|
| 556 |
If the SMU channel is setup as a variable (VAR1, VAR2, VARD) then compliance limits are |
| 557 |
set by the variable definition. |
| 558 |
|
| 559 |
- Value: Voltage in (-200V, 200V) and current in (-1A, 1A) based |
| 560 |
on :meth:`~.SMU.channel_mode`. |
| 561 |
|
| 562 |
.. code-block:: python |
| 563 |
|
| 564 |
instr.smu1.compliance = 0.1 |
| 565 |
""" |
| 566 |
if Agilent4156.analyzer_mode.fget(self) == "SWEEP": |
| 567 |
value = self.ask(f":PAGE:MEAS:CONS:{self.channel}:COMP?") |
| 568 |
else: |
| 569 |
value = self.ask( |
| 570 |
f":PAGE:MEAS:SAMP:CONS:{self.channel}:COMP?") |
| 571 |
self.check_errors() |
| 572 |
return value |
| 573 |
|
| 574 |
@compliance.setter |
| 575 |
def compliance(self, comp): |
| 576 |
validator = strict_range |
| 577 |
values = self.__validate_compl() |
| 578 |
value = validator(comp, values) |
| 579 |
if Agilent4156.analyzer_mode.fget(self) == 'SWEEP': |
| 580 |
self.write(":PAGE:MEAS:CONS:{}:COMP {}".format( |
| 581 |
self.channel, value)) |
| 582 |
else: |
| 583 |
self.write(":PAGE:MEAS:SAMP:CONS:{}:COMP {}".format( |
| 584 |
self.channel, value)) |
| 585 |
self.check_errors() |
| 586 |
|
| 587 |
@property |
| 588 |
def voltage_name(self): |
| 589 |
""" Define the voltage name of the channel. |
| 590 |
|
| 591 |
If input is greater than 6 characters long or starts with a number, |
| 592 |
the name is autocorrected and prepended with 'a'. Event is logged. |
| 593 |
|
| 594 |
.. code-block:: python |
| 595 |
|
| 596 |
instr.smu1.voltage_name = "Vbase" |
| 597 |
""" |
| 598 |
value = self.ask(f"PAGE:CHAN:{self.channel}:VNAME?") |
| 599 |
return value |
| 600 |
|
| 601 |
@voltage_name.setter |
| 602 |
def voltage_name(self, vname): |
| 603 |
value = check_current_voltage_name(vname) |
| 604 |
self.write(f":PAGE:CHAN:{self.channel}:VNAME \'{value}\'") |
| 605 |
|
| 606 |
@property |
| 607 |
def current_name(self): |
| 608 |
""" Define the current name of the channel. |
| 609 |
|
| 610 |
If input is greater than 6 characters long or starts with a number, |
| 611 |
the name is autocorrected and prepended with 'a'. Event is logged. |
| 612 |
|
| 613 |
.. code-block:: python |
| 614 |
|
| 615 |
instr.smu1.current_name = "Ibase" |
| 616 |
""" |
| 617 |
value = self.ask(f"PAGE:CHAN:{self.channel}:INAME?") |
| 618 |
return value |
| 619 |
|
| 620 |
@current_name.setter |
| 621 |
def current_name(self, iname): |
| 622 |
value = check_current_voltage_name(iname) |
| 623 |
self.write(f":PAGE:CHAN:{self.channel}:INAME \'{value}\'") |
| 624 |
|
| 625 |
def __validate_cons(self): |
| 626 |
"""Validates the instrument settings for operation in constant mode. |
| 627 |
""" |
| 628 |
if not ((self.channel_mode != 'COMM') and ( |
| 629 |
self.channel_function == 'CONS')): |
| 630 |
raise ValueError( |
| 631 |
'Cannot set constant SMU function when SMU mode is COMMON, ' |
| 632 |
'or when SMU function is not CONSTANT.' |
| 633 |
) |
| 634 |
else: |
| 635 |
values = valid_iv(self.channel_mode) |
| 636 |
return values |
| 637 |
|
| 638 |
def __validate_compl(self): |
| 639 |
"""Validates the instrument compliance for operation in constant mode. |
| 640 |
""" |
| 641 |
if not ((self.channel_mode != 'COMM') and ( |
| 642 |
self.channel_function == 'CONS')): |
| 643 |
raise ValueError( |
| 644 |
'Cannot set constant SMU parameters when SMU mode is COMMON, ' |
| 645 |
'or when SMU function is not CONSTANT.' |
| 646 |
) |
| 647 |
else: |
| 648 |
values = valid_compliance(self.channel_mode) |
| 649 |
return values |
| 650 |
|
| 651 |
|
| 652 |
class VMU(SCPIUnknownMixin, Instrument): |
| 653 |
def __init__(self, adapter, channel, **kwargs): |
| 654 |
super().__init__( |
| 655 |
adapter, |
| 656 |
"VMU of Agilent 4155/4156 Semiconductor Parameter Analyzer", |
| 657 |
**kwargs |
| 658 |
) |
| 659 |
self.channel = channel.upper() |
| 660 |
|
| 661 |
@property |
| 662 |
def voltage_name(self): |
| 663 |
""" Define the voltage name of the VMU channel. |
| 664 |
|
| 665 |
If input is greater than 6 characters long or starts with a number, |
| 666 |
the name is autocorrected and prepended with 'a'. Event is logged. |
| 667 |
|
| 668 |
.. code-block:: python |
| 669 |
|
| 670 |
instr.vmu1.voltage_name = "Vanode" |
| 671 |
""" |
| 672 |
value = self.ask(f"PAGE:CHAN:{self.channel}:VNAME?") |
| 673 |
return value |
| 674 |
|
| 675 |
@voltage_name.setter |
| 676 |
def voltage_name(self, vname): |
| 677 |
value = check_current_voltage_name(vname) |
| 678 |
self.write(f":PAGE:CHAN:{self.channel}:VNAME \'{value}\'") |
| 679 |
|
| 680 |
@property |
| 681 |
def disable(self): |
| 682 |
""" Disables the settings of VMU<n>. |
| 683 |
|
| 684 |
.. code-block:: python |
| 685 |
|
| 686 |
instr.vmu1.disable() |
| 687 |
""" |
| 688 |
self.write(f":PAGE:CHAN:{self.channel}:DIS") |
| 689 |
self.check_errors() |
| 690 |
|
| 691 |
@property |
| 692 |
def channel_mode(self): |
| 693 |
""" A string property that controls the VMU<n> channel mode. |
| 694 |
|
| 695 |
- Values: :code:`V`, :code:`DVOL` |
| 696 |
""" |
| 697 |
value = self.ask(f":PAGE:CHAN:{self.channel}:MODE?") |
| 698 |
self.check_errors() |
| 699 |
return value |
| 700 |
|
| 701 |
@channel_mode.setter |
| 702 |
def channel_mode(self, mode): |
| 703 |
validator = strict_discrete_set |
| 704 |
values = ["V", "DVOL"] |
| 705 |
value = validator(mode, values) |
| 706 |
self.write(f":PAGE:CHAN:{self.channel}:MODE {value}") |
| 707 |
self.check_errors() |
| 708 |
|
| 709 |
|
| 710 |
class VSU(SCPIUnknownMixin, Instrument): |
| 711 |
def __init__(self, adapter, channel, **kwargs): |
| 712 |
super().__init__( |
| 713 |
adapter, |
| 714 |
"VSU of Agilent 4155/4156 Semiconductor Parameter Analyzer", |
| 715 |
**kwargs |
| 716 |
) |
| 717 |
self.channel = channel.upper() |
| 718 |
|
| 719 |
@property |
| 720 |
def voltage_name(self): |
| 721 |
""" Define the voltage name of the VSU channel |
| 722 |
|
| 723 |
If input is greater than 6 characters long or starts with a number, |
| 724 |
the name is autocorrected and prepended with 'a'. Event is logged. |
| 725 |
|
| 726 |
.. code-block:: python |
| 727 |
|
| 728 |
instr.vsu1.voltage_name = "Ve" |
| 729 |
""" |
| 730 |
value = self.ask(f"PAGE:CHAN:{self.channel}:VNAME?") |
| 731 |
return value |
| 732 |
|
| 733 |
@voltage_name.setter |
| 734 |
def voltage_name(self, vname): |
| 735 |
value = check_current_voltage_name(vname) |
| 736 |
self.write(f":PAGE:CHAN:{self.channel}:VNAME \'{value}\'") |
| 737 |
|
| 738 |
@property |
| 739 |
def disable(self): |
| 740 |
""" Deletes the settings of VSU<n>. |
| 741 |
|
| 742 |
.. code-block:: python |
| 743 |
|
| 744 |
instr.vsu1.disable() |
| 745 |
""" |
| 746 |
self.write(f":PAGE:CHAN:{self.channel}:DIS") |
| 747 |
self.check_errors() |
| 748 |
|
| 749 |
@property |
| 750 |
def channel_mode(self): |
| 751 |
""" Get channel mode of VSU<n>.""" |
| 752 |
value = self.ask(f":PAGE:CHAN:{self.channel}:MODE?") |
| 753 |
self.check_errors() |
| 754 |
return value |
| 755 |
|
| 756 |
@property |
| 757 |
def constant_value(self): |
| 758 |
""" Sets the constant source value of VSU<n>. |
| 759 |
|
| 760 |
.. code-block:: python |
| 761 |
|
| 762 |
instr.vsu1.constant_value = 0 |
| 763 |
""" |
| 764 |
if Agilent4156.analyzer_mode.fget(self) == "SWEEP": |
| 765 |
value = self.ask(f":PAGE:MEAS:CONS:{self.channel}?") |
| 766 |
else: |
| 767 |
value = self.ask(f":PAGE:MEAS:SAMP:CONS:{self.channel}?") |
| 768 |
self.check_errors() |
| 769 |
return value |
| 770 |
|
| 771 |
@constant_value.setter |
| 772 |
def constant_value(self, const_value): |
| 773 |
validator = strict_range |
| 774 |
values = [-200, 200] |
| 775 |
value = validator(const_value, values) |
| 776 |
if Agilent4156.analyzer_mode.fget(self) == 'SWEEP': |
| 777 |
self.write(f":PAGE:MEAS:CONS:{self.channel} {value}") |
| 778 |
else: |
| 779 |
self.write(":PAGE:MEAS:SAMP:CONS:{} {}".format( |
| 780 |
self.channel, value)) |
| 781 |
self.check_errors() |
| 782 |
|
| 783 |
@property |
| 784 |
def channel_function(self): |
| 785 |
""" A string property that controls the VSU channel function. |
| 786 |
|
| 787 |
- Value: :code:`VAR1`, :code:`VAR2`, :code:`VARD` or :code:`CONS`. |
| 788 |
""" |
| 789 |
value = self.ask(f":PAGE:CHAN:{self.channel}:FUNC?") |
| 790 |
self.check_errors() |
| 791 |
return value |
| 792 |
|
| 793 |
@channel_function.setter |
| 794 |
def channel_function(self, function): |
| 795 |
validator = strict_discrete_set |
| 796 |
values = ["VAR1", "VAR2", "VARD", "CONS"] |
| 797 |
value = validator(function, values) |
| 798 |
self.write(f":PAGE:CHAN:{self.channel}:FUNC {value}") |
| 799 |
self.check_errors() |
| 800 |
|
| 801 |
################# |
| 802 |
# SWEEP VARIABLES |
| 803 |
################# |
| 804 |
|
| 805 |
|
| 806 |
class VARX(SCPIUnknownMixin, Instrument): |
| 807 |
""" Base class to define sweep variable settings """ |
| 808 |
|
| 809 |
def __init__(self, adapter, var_name, **kwargs): |
| 810 |
super().__init__( |
| 811 |
adapter, |
| 812 |
"Methods to setup sweep variables", |
| 813 |
**kwargs |
| 814 |
) |
| 815 |
self.var = var_name.upper() |
| 816 |
|
| 817 |
@property |
| 818 |
def channel_mode(self): |
| 819 |
channels = ['SMU1', 'SMU2', 'SMU3', 'SMU4', 'VSU1', 'VSU2'] |
| 820 |
for ch in channels: |
| 821 |
ch_func = self.ask(f":PAGE:CHAN:{ch}:FUNC?") |
| 822 |
if ch_func == self.var: |
| 823 |
ch_mode = self.ask(f":PAGE:CHAN:{ch}:MODE?") |
| 824 |
return ch_mode |
| 825 |
|
| 826 |
@property |
| 827 |
def start(self): |
| 828 |
""" Sets the sweep START value. |
| 829 |
|
| 830 |
.. code-block:: python |
| 831 |
|
| 832 |
instr.var1.start = 0 |
| 833 |
""" |
| 834 |
value = self.ask(f":PAGE:MEAS:{self.var}:STAR?") |
| 835 |
self.check_errors() |
| 836 |
return value |
| 837 |
|
| 838 |
@start.setter |
| 839 |
def start(self, value): |
| 840 |
validator = strict_range |
| 841 |
values = valid_iv(self.channel_mode) |
| 842 |
set_value = validator(value, values) |
| 843 |
self.write(f":PAGE:MEAS:{self.var}:STAR {set_value}") |
| 844 |
self.check_errors() |
| 845 |
|
| 846 |
@property |
| 847 |
def stop(self): |
| 848 |
""" Sets the sweep STOP value. |
| 849 |
|
| 850 |
.. code-block:: python |
| 851 |
|
| 852 |
instr.var1.stop = 3 |
| 853 |
""" |
| 854 |
value = self.ask(f":PAGE:MEAS:{self.var}:STOP?") |
| 855 |
self.check_errors() |
| 856 |
return value |
| 857 |
|
| 858 |
@stop.setter |
| 859 |
def stop(self, value): |
| 860 |
validator = strict_range |
| 861 |
values = valid_iv(self.channel_mode) |
| 862 |
set_value = validator(value, values) |
| 863 |
self.write(f":PAGE:MEAS:{self.var}:STOP {set_value}") |
| 864 |
self.check_errors() |
| 865 |
|
| 866 |
@property |
| 867 |
def step(self): |
| 868 |
""" Sets the sweep STEP value. |
| 869 |
|
| 870 |
.. code-block:: python |
| 871 |
|
| 872 |
instr.var1.step = 0.1 |
| 873 |
""" |
| 874 |
value = self.ask(f":PAGE:MEAS:{self.var}:STEP?") |
| 875 |
self.check_errors() |
| 876 |
return value |
| 877 |
|
| 878 |
@step.setter |
| 879 |
def step(self, value): |
| 880 |
validator = strict_range |
| 881 |
values = 2 * valid_iv(self.channel_mode) |
| 882 |
set_value = validator(value, values) |
| 883 |
self.write(f":PAGE:MEAS:{self.var}:STEP {set_value}") |
| 884 |
self.check_errors() |
| 885 |
|
| 886 |
@property |
| 887 |
def compliance(self): |
| 888 |
""" Sets the sweep COMPLIANCE value. |
| 889 |
|
| 890 |
.. code-block:: python |
| 891 |
|
| 892 |
instr.var1.compliance = 0.1 |
| 893 |
""" |
| 894 |
value = self.ask(":PAGE:MEAS:{}:COMP?") |
| 895 |
self.check_errors() |
| 896 |
return value |
| 897 |
|
| 898 |
@compliance.setter |
| 899 |
def compliance(self, value): |
| 900 |
validator = strict_range |
| 901 |
values = 2 * valid_compliance(self.channel_mode) |
| 902 |
set_value = validator(value, values) |
| 903 |
self.write(f":PAGE:MEAS:{self.var}:COMP {set_value}") |
| 904 |
self.check_errors() |
| 905 |
|
| 906 |
|
| 907 |
class VAR1(VARX): |
| 908 |
""" Class to handle all the specific definitions needed for VAR1. |
| 909 |
Most common methods are inherited from base class. |
| 910 |
""" |
| 911 |
|
| 912 |
def __init__(self, adapter, **kwargs): |
| 913 |
super().__init__( |
| 914 |
adapter, |
| 915 |
"VAR1", |
| 916 |
**kwargs |
| 917 |
) |
| 918 |
|
| 919 |
spacing = Instrument.control( |
| 920 |
":PAGE:MEAS:VAR1:SPAC?", |
| 921 |
":PAGE:MEAS:VAR1:SPAC %s", |
| 922 |
""" |
| 923 |
Selects the sweep type of VAR1. |
| 924 |
|
| 925 |
- Values: :code:`LINEAR`, :code:`LOG10`, :code:`LOG25`, :code:`LOG50`. |
| 926 |
""", |
| 927 |
validator=strict_discrete_set, |
| 928 |
values={'LINEAR': 'LIN', 'LOG10': 'L10', |
| 929 |
'LOG25': 'L25', 'LOG50': 'L50'}, |
| 930 |
map_values=True, |
| 931 |
check_set_errors=True, |
| 932 |
check_get_errors=True |
| 933 |
) |
| 934 |
|
| 935 |
|
| 936 |
class VAR2(VARX): |
| 937 |
""" Class to handle all the specific definitions needed for VAR2. |
| 938 |
Common methods are imported from base class. |
| 939 |
""" |
| 940 |
|
| 941 |
def __init__(self, adapter, **kwargs): |
| 942 |
super().__init__( |
| 943 |
adapter, |
| 944 |
"VAR2", |
| 945 |
**kwargs |
| 946 |
) |
| 947 |
|
| 948 |
points = Instrument.control( |
| 949 |
":PAGE:MEAS:VAR2:POINTS?", |
| 950 |
":PAGE:MEAS:VAR2:POINTS %g", |
| 951 |
""" |
| 952 |
Sets the number of sweep steps of VAR2. |
| 953 |
You use this command only if there is an SMU or VSU |
| 954 |
whose function (FCTN) is VAR2. |
| 955 |
|
| 956 |
.. code-block:: python |
| 957 |
|
| 958 |
instr.var2.points = 10 |
| 959 |
""", |
| 960 |
validator=strict_discrete_set, |
| 961 |
values=range(1, 128), |
| 962 |
check_set_errors=True, |
| 963 |
check_get_errors=True |
| 964 |
) |
| 965 |
|
| 966 |
|
| 967 |
class VARD(SCPIUnknownMixin, Instrument): |
| 968 |
""" Class to handle all the definitions needed for VARD. |
| 969 |
VARD is always defined in relation to VAR1. |
| 970 |
""" |
| 971 |
|
| 972 |
def __init__(self, adapter, **kwargs): |
| 973 |
super().__init__( |
| 974 |
adapter, |
| 975 |
"Definitions for VARD sweep variable.", |
| 976 |
**kwargs |
| 977 |
) |
| 978 |
|
| 979 |
@property |
| 980 |
def channel_mode(self): |
| 981 |
channels = ['SMU1', 'SMU2', 'SMU3', 'SMU4', 'VSU1', 'VSU2'] |
| 982 |
for ch in channels: |
| 983 |
ch_func = self.ask(f":PAGE:CHAN:{ch}:FUNC?") |
| 984 |
if ch_func == "VARD": |
| 985 |
ch_mode = self.ask(f":PAGE:CHAN:{ch}:MODE?") |
| 986 |
return ch_mode |
| 987 |
|
| 988 |
@property |
| 989 |
def offset(self): |
| 990 |
""" |
| 991 |
Sets the OFFSET value of VARD. |
| 992 |
For each step of sweep, the output values of VAR1' are determined by the |
| 993 |
following equation: VARD = VAR1 X RATio + OFFSet |
| 994 |
You use this command only if there is an SMU or VSU whose function is VARD. |
| 995 |
|
| 996 |
.. code-block:: python |
| 997 |
|
| 998 |
instr.vard.offset = 1 |
| 999 |
""" |
| 1000 |
value = self.ask(":PAGE:MEAS:VARD:OFFSET?") |
| 1001 |
self.check_errors() |
| 1002 |
return value |
| 1003 |
|
| 1004 |
@offset.setter |
| 1005 |
def offset(self, offset_value): |
| 1006 |
validator = strict_range |
| 1007 |
values = 2 * valid_iv(self.channel_mode) |
| 1008 |
value = validator(offset_value, values) |
| 1009 |
self.write(f":PAGE:MEAS:VARD:OFFSET {value}") |
| 1010 |
self.check_errors() |
| 1011 |
|
| 1012 |
ratio = Instrument.control( |
| 1013 |
":PAGE:MEAS:VARD:RATIO?", |
| 1014 |
":PAGE:MEAS:VARD:RATIO %g", |
| 1015 |
""" |
| 1016 |
Sets the RATIO of VAR1'. |
| 1017 |
For each step of sweep, the output values of VAR1' are determined by the |
| 1018 |
following equation: VAR1’ = VAR1 * RATio + OFFSet |
| 1019 |
You use this command only if there is an SMU or VSU whose function |
| 1020 |
(FCTN) is VAR1'. |
| 1021 |
|
| 1022 |
.. code-block:: python |
| 1023 |
|
| 1024 |
instr.vard.ratio = 1 |
| 1025 |
""", |
| 1026 |
) |
| 1027 |
|
| 1028 |
@property |
| 1029 |
def compliance(self): |
| 1030 |
""" Sets the sweep COMPLIANCE value of VARD. |
| 1031 |
|
| 1032 |
.. code-block:: python |
| 1033 |
|
| 1034 |
instr.vard.compliance = 0.1 |
| 1035 |
""" |
| 1036 |
value = self.ask(":PAGE:MEAS:VARD:COMP?") |
| 1037 |
self.check_errors() |
| 1038 |
return value |
| 1039 |
|
| 1040 |
@compliance.setter |
| 1041 |
def compliance(self, value): |
| 1042 |
validator = strict_range |
| 1043 |
values = 2 * valid_compliance(self.channel_mode) |
| 1044 |
set_value = validator(value, values) |
| 1045 |
self.write(f":PAGE:MEAS:VARD:COMP {set_value}") |
| 1046 |
self.check_errors() |
| 1047 |
|
| 1048 |
|
| 1049 |
def check_current_voltage_name(name): |
| 1050 |
if (len(name) > 6) or not name[0].isalpha(): |
| 1051 |
new_name = 'a' + name[:5] |
| 1052 |
log.info(f"Renaming {name} to {new_name}...") |
| 1053 |
name = new_name |
| 1054 |
return name |
| 1055 |
|
| 1056 |
|
| 1057 |
def valid_iv(channel_mode): |
| 1058 |
if channel_mode == 'V': |
| 1059 |
values = [-200, 200] |
| 1060 |
elif channel_mode == 'I': |
| 1061 |
values = [-1, 1] |
| 1062 |
else: |
| 1063 |
raise ValueError( |
| 1064 |
'Channel is not in V or I mode. It might be disabled.') |
| 1065 |
return values |
| 1066 |
|
| 1067 |
|
| 1068 |
def valid_compliance(channel_mode): |
| 1069 |
if channel_mode == 'I': |
| 1070 |
values = [-200, 200] |
| 1071 |
elif channel_mode == 'V': |
| 1072 |
values = [-1, 1] |
| 1073 |
else: |
| 1074 |
raise ValueError( |
| 1075 |
'Channel is not in V or I mode. It might be disabled.') |
| 1076 |
return values |