Debian Codegraph @

pymeasure/instruments/hp/hp11713a.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 import logging
25 from pymeasure.instruments import Instrument, Channel
26
27 log = logging.getLogger(__name__)
28 log.addHandler(logging.NullHandler())
29
30 Attenuator_11dB = {
31 0: (False, False, False, False),
32 1: (True, False, False, False),
33 2: (False, True, False, False),
34 3: (True, True, False, False),
35 4: (False, False, False, True),
36 5: (True, False, False, True),
37 6: (False, True, False, True),
38 7: (True, True, False, True),
39 8: (False, False, True, True),
40 9: (True, False, True, True),
41 10: (False, True, True, True),
42 11: (True, True, True, True),
43 }
44 """ Mapping of logical values for use with 0 - 11 dB attenuators """
45
46 Attenuator_110dB = {
47 0: (False, False, False, False),
48 10: (True, False, False, False),
49 20: (False, True, False, False),
50 30: (True, True, False, False),
51 40: (False, False, False, True),
52 50: (True, False, False, True),
53 60: (False, True, False, True),
54 70: (True, True, False, True),
55 80: (False, False, True, True),
56 90: (True, False, True, True),
57 100: (False, True, True, True),
58 110: (True, True, True, True),
59 }
60 """ Mapping of logical values for use with 0 - 110 dB attenuators """
61
62 Attenuator_70dB_3_Section = {
63 0: (False, False, False, False),
64 10: (True, False, False, False),
65 20: (False, True, False, False),
66 30: (True, True, False, False),
67 40: (False, False, True, False),
68 50: (True, False, True, False),
69 60: (False, True, True, False),
70 70: (True, True, True, False),
71 }
72 """ Mapping of logical values for use with 0 - 70 dB attenuators with 3 switching sections """
73
74 Attenuator_70dB_4_Section = {
75 0: (False, False, False, False),
76 10: (True, False, False, False),
77 20: (False, False, False, True),
78 30: (True, False, False, True),
79 40: (False, True, False, True),
80 50: (True, True, False, True),
81 60: (False, True, True, True),
82 70: (True, True, True, True),
83 }
84 """ Mapping of logical values for use with 0 - 70 dB attenuators with 4 switching sections """
85
86
87 class SwitchDriverChannel(Channel):
88 enabled = Instrument.setting(
89 "%s{ch}",
90 """
91 Set this channel to the polarity 'A' for True and 'B' for False.
92 """,
93 map_values=True,
94 values={True: "A", False: "B"}
95 )
96
97
98 class HP11713A(Instrument):
99 """
100 Represents the HP 11713A Switch and Attenuator Driver and provides a high-level
101 interface for interacting with the instrument.
102
103 Usually an attenuator is hooked to either X or Y or X and Y. To ease the control
104 of the attenuator driver you have the possibility to set an attenuator type via
105 the attribute 'ATTENUATOR_X' or 'ATTENUATOR_Y'. The hp11713a keeps different default attenuator
106 mappings. After setting the attenuator type you are able to use the methods 'attenuation_x'
107 and/or 'attenuation_y' to set the switch driver to the correct value for the specified
108 attenuation. The attenuation values are rounded.
109
110 .. code-block:: python
111
112 from pymeasure.instruments.hp import HP11713A
113 from pymeasure.instruments.hp.hp11713a import Attenuator_110dB
114
115 sd = HP11713A("GPIB::1")
116
117 sd.ATTENUATOR_Y = Attenuator_110dB
118 sd.attenuation_y(10)
119 sd.ch_0.enabled = True
120
121 """
122
123 ATTENUATOR_X = {}
124 ATTENUATOR_Y = {}
125
126 channels = Instrument.MultiChannelCreator(SwitchDriverChannel, list(range(0, 9)))
127
128 def __init__(self, adapter, name="Hewlett-Packard HP11713A",
129 **kwargs):
130 super().__init__(
131 adapter,
132 name,
133 includeSCPI=False,
134 send_end=True,
135 **kwargs,
136 )
137
138 def attenuation_x(self, attenuation):
139 """ Set switches according to the attenuation in dB for X
140
141 The set attenuation will be rounded to the next available step.
142 An attenuation mapping has to be set in before e.g.
143
144 .. code-block:: python
145
146 from pymeasure.instruments.hp.hp11713a import HP11713A, Attenuator_110dB
147
148 instr.ATTENUATOR_X = Attenuator_110dB
149 instr.attenuation_x(10)
150 """
151 rounding = 0
152 if list(self.ATTENUATOR_X.keys())[1] == 10:
153 rounding = -1
154
155 self.ch_1.enabled, self.ch_2.enabled, self.ch_3.enabled, self.ch_4.enabled = \
156 self.ATTENUATOR_X[int(round(attenuation, rounding))]
157
158 def attenuation_y(self, attenuation):
159 """ Set switches according to the attenuation in dB for Y
160
161 The set attenuation will be rounded to the next available step.
162 An attenuation mapping has to be set in before e.g.
163
164 .. code-block:: python
165
166 from pymeasure.instruments.hp.hp11713a import HP11713A, Attenuator_110dB
167
168 instr.ATTENUATOR_Y = Attenuator_110dB
169 instr.attenuation_y(10)
170 """
171 rounding = 0
172 if list(self.ATTENUATOR_Y.keys())[1] == 10:
173 rounding = -1
174
175 self.ch_5.enabled, self.ch_6.enabled, self.ch_7.enabled, self.ch_8.enabled = \
176 self.ATTENUATOR_Y[int(round(attenuation, rounding))]
177
178 def deactivate_all(self):
179 """
180 Deactivate all switches to polarity 'B'.
181 """
182 self.write("B1234567890")