Debian Codegraph @

pymeasure/instruments/bkprecision/bkprecision9130b.py

raw
1 #
2 # This file is part of the PyMeasure package.
3 #
4 # Copyright (c) 2013-2024 PyMeasure Developers
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 # THE SOFTWARE.
23 #
24
25 from pymeasure.instruments import Instrument, SCPIUnknownMixin
26 from pymeasure.instruments.validators import strict_discrete_set, truncated_range
27
28 CHANNEL_NUMS = [1, 2, 3]
29
30
31 class BKPrecision9130B(SCPIUnknownMixin, Instrument):
32 """ Represents the BK Precision 9130B DC Power Supply interface for interacting with
33 the instrument. """
34
35 current = Instrument.control(
36 'MEASure:SCALar:CURRent:DC?',
37 'SOURce:CURRent:LEVel:IMMediate:AMPLitude %g',
38 """Control the current of the selected channel. (float)""",
39 validator=truncated_range,
40 values=[0, 3]
41 )
42
43 source_enabled = Instrument.control(
44 'SOURce:CHANnel:OUTPut:STATe?',
45 'SOURce:CHANnel:OUTPut:STATe %d',
46 """Control whether the source is enabled. (bool) """,
47 validator=strict_discrete_set,
48 values={True: 1, False: 0},
49 map_values=True
50 )
51
52 channel = Instrument.control(
53 'INSTrument:SELect?',
54 'INSTrument:SELect CH%d',
55 f"""Control which channel is selected. Can only take
56 values {CHANNEL_NUMS}. (int)""",
57 validator=strict_discrete_set,
58 values=CHANNEL_NUMS,
59 get_process=lambda x: int(x[2])
60 )
61
62 def __init__(self, adapter, name="BK Precision 9130B Source", **kwargs):
63 super().__init__(
64 adapter, name, **kwargs
65 )
66
67 @property
68 def voltage(self):
69 """Control voltage of the selected channel. (float)"""
70 return float(self.ask("MEASure:SCALar:VOLTage:DC?"))
71
72 @voltage.setter
73 def voltage(self, level):
74 voltage_range = [0, 5] if self.channel == 3 else [0, 30]
75 new_level = truncated_range(level, voltage_range)
76 self.write("SOURce:VOLTage:LEVel:IMMediate:AMPLitude %g" % new_level)