Debian Codegraph @

pymeasure/instruments/mksinst/mks937b.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 Channel, Instrument
26 from pymeasure.instruments.validators import strict_discrete_set
27
28 from .mksinst import MKSInstrument, RelayChannel
29
30
31 try:
32 from enum import StrEnum
33 except ImportError:
34 from enum import Enum
35
36 class StrEnum(str, Enum):
37 """Until StrEnum is broadly available from the standard library"""
38 # Python>3.10 remove it
39
40
41 _ion_gauge_status = {"Wait": "W",
42 "Off": "O",
43 "Protect": "P",
44 "Degas": "D",
45 "Control": "C",
46 "Rear panel Ctrl off": "R",
47 "HC filament fault": "H",
48 "No gauge": "N",
49 "Good": "G",
50 "NOT_IONGAUGE": "NAK152",
51 "INVALID COMMAND": "NAK160",
52 }
53
54
55 class Unit(StrEnum):
56 Torr = "TORR"
57 mbar = "mBAR"
58 Pa = "PASCAL"
59 uHg = "MICRON"
60
61
62 class Relay(RelayChannel):
63
64 enabled = Channel.control(
65 "EN{ch}?", "EN{ch}!%s",
66 """Control the relay function or disable the setpoint relay.
67
68 Possible values are True/False to enable/disable pressure based
69 activation of the relay and 'SET' to permanently energize the relay.""",
70 validator=strict_discrete_set,
71 map_values=True,
72 values={False: "CLEAR",
73 True: "ENABLE",
74 "SET": "SET",
75 },
76 check_set_errors=True,
77 )
78
79
80 class PressureChannel(Channel):
81 pressure = Channel.measurement(
82 "PR{ch}?",
83 """Get the pressure on the channel in units selected on the device""",
84 )
85
86 power_enabled = Channel.control(
87 "CP{ch}?", "CP{ch}!%s",
88 """Control power status of the channel. (bool)""",
89 validator=strict_discrete_set,
90 map_values=True,
91 values={True: "ON", False: "OFF"},
92 check_set_errors=True,
93 )
94
95
96 class IonGaugeAndPressureChannel(PressureChannel):
97 """Channel having both a pressure and an ion gauge sensor"""
98 ion_gauge_status = Channel.measurement(
99 "T{ch}?",
100 """Get ion gauge status of the channel.""",
101 map_values=True,
102 values=_ion_gauge_status,
103 )
104
105
106 class MKS937B(MKSInstrument):
107 """ MKS 937B vacuum gauge controller
108
109 Connection to the device is made through an RS232/RS485 serial connection.
110
111 The 937B gauge controller can connect up to 6 pressure measurement channels
112 for gauges of various types which includes ionization gauges, Pirani and
113 piezo gauges. Based on the pressure values of the gauges twelve setpoint
114 relays can be energized when certain pressure values are reached. The
115 assignment of the relays to measurement channels is fixed to have two
116 relays for each pressure channel.
117
118 :param adapter: pyvisa resource name of the instrument or adapter instance
119 :param string name: The name of the instrument.
120 :param address: device address included in every message to the instrument
121 (default=253)
122 :param kwargs: Any valid key-word argument for Instrument
123 """
124
125 # Channels 1,3,5 have both an ion gauge and a pressure sensor, 2,4,6 only a pressure sensor
126 ch_1 = Instrument.ChannelCreator(IonGaugeAndPressureChannel, 1)
127
128 ch_2 = Instrument.ChannelCreator(PressureChannel, 2)
129
130 ch_3 = Instrument.ChannelCreator(IonGaugeAndPressureChannel, 3)
131
132 ch_4 = Instrument.ChannelCreator(PressureChannel, 4)
133
134 ch_5 = Instrument.ChannelCreator(IonGaugeAndPressureChannel, 5)
135
136 ch_6 = Instrument.ChannelCreator(PressureChannel, 6)
137
138 relay_1 = Instrument.ChannelCreator(Relay, 1)
139
140 relay_2 = Instrument.ChannelCreator(Relay, 2)
141
142 relay_3 = Instrument.ChannelCreator(Relay, 3)
143
144 relay_4 = Instrument.ChannelCreator(Relay, 4)
145
146 relay_5 = Instrument.ChannelCreator(Relay, 5)
147
148 relay_6 = Instrument.ChannelCreator(Relay, 6)
149
150 relay_7 = Instrument.ChannelCreator(Relay, 7)
151
152 relay_8 = Instrument.ChannelCreator(Relay, 8)
153
154 relay_9 = Instrument.ChannelCreator(Relay, 9)
155
156 relay_10 = Instrument.ChannelCreator(Relay, 10)
157
158 relay_11 = Instrument.ChannelCreator(Relay, 11)
159
160 relay_12 = Instrument.ChannelCreator(Relay, 12)
161
162 def __init__(self, adapter, name="MKS 937B vacuum gauge controller", address=253, **kwargs):
163 super().__init__(
164 adapter,
165 name,
166 address=address,
167 **kwargs
168 )
169
170 serial = Instrument.measurement(
171 "SN?", """Get the serial number of the instrument """,
172 cast=str,
173 )
174
175 all_pressures = Instrument.measurement(
176 "PRZ?", """ Get pressures on all channels in selected units """,
177 )
178
179 combined_pressure1 = Instrument.measurement(
180 "PC1?", """ Get pressure on channel 1 and its combination sensor """,
181 )
182
183 combined_pressure2 = Instrument.measurement(
184 "PC2?", """ Get pressure on channel 2 and its combination sensor """,
185 )
186
187 unit = Instrument.control(
188 "U?", "U!%s",
189 """Control pressure unit used for all pressure readings from the instrument.
190
191 Allowed units are Unit.Torr, Unit.mbar, Unit.Pa, Unit.uHg.""",
192 validator=strict_discrete_set,
193 map_values=True,
194 values={u: u.value for u in Unit},
195 check_set_errors=True,
196 )