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