-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #990 from OptimisticBeliever/master
Add KeysightE3631A
- Loading branch information
Showing
7 changed files
with
292 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,4 +65,5 @@ Robert Roos | |
Sebastien Weber | ||
Sebastian Neusch | ||
Ulrich Sauter | ||
Guus Kuiper | ||
Guus Kuiper | ||
Armindo Pinto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
########################################## | ||
Keysight E3631A Triple Output Power Supply | ||
########################################## | ||
|
||
.. autoclass:: pymeasure.instruments.keysight.KeysightE3631A | ||
:members: | ||
:show-inheritance: | ||
:inherited-members: | ||
|
||
.. autoclass:: pymeasure.instruments.keysight.keysightE3631A.VoltageChannel | ||
:members: | ||
:show-inheritance: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
# | ||
# This file is part of the PyMeasure package. | ||
# | ||
# Copyright (c) 2013-2023 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 logging | ||
|
||
from pymeasure.instruments import Instrument, Channel | ||
from pymeasure.instruments.validators import strict_range, strict_discrete_set | ||
|
||
log = logging.getLogger(__name__) | ||
log.addHandler(logging.NullHandler()) | ||
|
||
|
||
class VoltageChannel(Channel): | ||
"""Implementation of a power supply base class channel""" | ||
|
||
voltage_setpoint = Channel.control( | ||
"INST:NSEL {ch};:VOLT?", | ||
"INST:NSEL {ch};:VOLT %g", | ||
"""Control the output voltage of this channel, range depends on channel.""", | ||
validator=strict_range, | ||
values=[0, 25], | ||
dynamic=True, | ||
) | ||
|
||
current_limit = Channel.control( | ||
"INST:NSEL {ch};:CURR?", | ||
"INST:NSEL {ch};:CURR %g", | ||
"""Control the current limit of this channel, range depends on channel.""", | ||
validator=strict_range, | ||
values=[0, 1], | ||
dynamic=True, | ||
) | ||
|
||
voltage = Channel.measurement( | ||
"INST:NSEL {ch};:MEAS:VOLT?", | ||
"""Measure actual voltage of this channel.""", | ||
) | ||
|
||
current = Channel.measurement( | ||
"INST:NSEL {ch};:MEAS:CURR?", | ||
"""Measure the actual current of this channel.""", | ||
) | ||
|
||
|
||
class KeysightE3631A(Instrument): | ||
""" Represents the Keysight E3631A Triple Output DC Power Supply | ||
interface for interacting with the instrument. | ||
.. code-block:: python | ||
supply = KeysightE3631A(resource) | ||
supply.ch_1.voltage_setpoint=10 | ||
supply.ch_1.current_setpoint=0.1 | ||
supply.ch_1.output_enabled=True | ||
print(supply.ch_1.voltage) | ||
""" | ||
|
||
ch_1 = Instrument.ChannelCreator(VoltageChannel, 1) | ||
|
||
ch_2 = Instrument.ChannelCreator(VoltageChannel, 2) | ||
|
||
ch_3 = Instrument.ChannelCreator(VoltageChannel, 3) | ||
|
||
def __init__(self, adapter, name="Keysight E3631A", **kwargs): | ||
super().__init__( | ||
adapter, name, includeSCPI=True, **kwargs | ||
) | ||
self.channels[1].voltage_setpoint_values = [0, 6] | ||
self.channels[1].current_limit_values = [0, 5] | ||
self.channels[3].voltage_setpoint_values = [0, -25] | ||
|
||
tracking_enabled = Instrument.control( | ||
":OUTP:TRAC?", | ||
":OUTP:TRAC %s", | ||
"""Control whether the power supply operates in the track mode (boolean)""", | ||
validator=strict_discrete_set, | ||
values={True: 1, False: 0}, | ||
map_values=True, | ||
) | ||
|
||
output_enabled = Instrument.control( | ||
"OUTPut?", | ||
"OUTPut %d", | ||
"""Control whether the channel output is enabled (boolean).""", | ||
validator=strict_discrete_set, | ||
map_values=True, | ||
values={True: 1, False: 0}, | ||
dynamic=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# | ||
# This file is part of the PyMeasure package. | ||
# | ||
# Copyright (c) 2013-2023 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 pytest | ||
from pymeasure.test import expected_protocol | ||
from pymeasure.instruments.keysight.keysightE3631A import KeysightE3631A | ||
|
||
|
||
def test_voltage_setpoint(): | ||
"""Verify the voltage setpoint setter and getter.""" | ||
with expected_protocol( | ||
KeysightE3631A, | ||
[("INST:NSEL 1;:VOLT 1.5", None), | ||
("INST:NSEL 1;:VOLT?", "1.5")], | ||
) as inst: | ||
inst.ch_1.voltage_setpoint = 1.5 | ||
assert inst.ch_1.voltage_setpoint == 1.5 | ||
|
||
|
||
def test_current_limit(): | ||
"""Verify the current limit setter and getter.""" | ||
with expected_protocol( | ||
KeysightE3631A, | ||
[("INST:NSEL 3;:CURR 0.5", None), | ||
("INST:NSEL 3;:CURR?", "0.5")], | ||
) as inst: | ||
inst.ch_3.current_limit = 0.5 | ||
assert inst.ch_3.current_limit == 0.5 | ||
|
||
|
||
def test_current_limit_validator(): | ||
"""Verify the current limit validator.""" | ||
with expected_protocol( | ||
KeysightE3631A, | ||
[], | ||
) as inst: | ||
with pytest.raises(ValueError, match="not in range"): | ||
inst.ch_1.current_limit = 7 | ||
|
||
|
||
def test_output_enabled(): | ||
"""Verify the output enable setter and getter.""" | ||
with expected_protocol( | ||
KeysightE3631A, | ||
[("OUTPut 1", None), | ||
("OUTPut?", "0")], | ||
) as inst: | ||
inst.output_enabled = True | ||
assert inst.output_enabled is False |
94 changes: 94 additions & 0 deletions
94
tests/instruments/keysight/test_keysightE3631A_with_device.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# | ||
# This file is part of the PyMeasure package. | ||
# | ||
# Copyright (c) 2013-2023 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 pytest | ||
from pymeasure.instruments.keysight.keysightE3631A import KeysightE3631A | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def power_supply(connected_device_address): | ||
instr = KeysightE3631A(connected_device_address) | ||
instr.reset() | ||
return instr | ||
|
||
|
||
class TestKeysightE3631A: | ||
""" | ||
Unit tests for KeysightE3631A class. | ||
This test suite, needs the following setup to work properly: | ||
- A KeysightE3631A device should be connected to the computer; | ||
- The device's address must be set in the RESOURCE constant; | ||
""" | ||
|
||
######################### | ||
# PARAMETRIZATION CASES # | ||
######################### | ||
|
||
BOOLEANS = [False, True] | ||
CHANNELS = [1, 2, 3] | ||
|
||
######### | ||
# TESTS # | ||
######### | ||
|
||
@pytest.mark.parametrize("case", BOOLEANS) | ||
def test_output_enabled(self, power_supply, case): | ||
assert not power_supply.output_enabled | ||
power_supply.output_enabled = case | ||
assert power_supply.output_enabled == case | ||
|
||
@pytest.mark.parametrize("case", BOOLEANS) | ||
def test_tracking_enabled(self, power_supply, case): | ||
assert not power_supply.tracking_enabled | ||
power_supply.tracking_enabled = case | ||
assert power_supply.tracking_enabled == case | ||
|
||
@pytest.mark.parametrize("chn, i_limit", [(1, 0), (1, 5), (2, 0), (2, 1), (3, 0), (3, 1)],) | ||
def test_current_limit(self, power_supply, chn, i_limit): | ||
power_supply.channels[chn].current_limit = i_limit | ||
|
||
@pytest.mark.parametrize("chn, i_limit", [(1, -1), (1, 6), (2, -1), (2, 2), (3, -1), (3, 2)],) | ||
def test_current_limit_out_of_range(self, power_supply, chn, i_limit): | ||
with pytest.raises(ValueError, match=f"Value of {i_limit} is not in range"): | ||
power_supply.channels[chn].current_limit = i_limit | ||
|
||
@pytest.mark.parametrize("chn, voltage", [(1, 0), (1, 6), (2, 0), (2, 25), (3, 0), (3, -25)],) | ||
def test_voltage_setpoint(self, power_supply, chn, voltage): | ||
power_supply.channels[chn].voltage_setpoint = voltage | ||
assert power_supply.channels[chn].voltage_setpoint == voltage | ||
|
||
@pytest.mark.parametrize("chn, voltage", | ||
[(1, -1), (1, 7), (2, -1), (2, 26), (3, 1), (3, -26)],) | ||
def test_voltage_setpoint_out_of_range(self, power_supply, chn, voltage): | ||
with pytest.raises(ValueError, match=f"Value of {voltage} is not in range"): | ||
power_supply.channels[chn].voltage_setpoint = voltage | ||
|
||
@pytest.mark.parametrize("chn", CHANNELS) | ||
def test_measure_voltage(self, power_supply, chn): | ||
assert isinstance(power_supply.channels[chn].voltage, float) | ||
|
||
@pytest.mark.parametrize("chn", CHANNELS) | ||
def test_measure_current(self, power_supply, chn): | ||
assert isinstance(power_supply.channels[chn].current, float) |