Debian Codegraph @

pymeasure/instruments/keithley/keithley2750.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, SCPIMixin
26
27
28 def clean_closed_channels(output):
29 """Cleans up the list returned by command ":ROUTe:CLOSe?", such that each entry is an integer
30 denoting the channel number.
31 """
32 if isinstance(output, str):
33 s = output.replace("(", "").replace(")", "").replace("@", "")
34 if s == "":
35 return []
36 else:
37 return [int(s)]
38 elif isinstance(output, list):
39 list_final = []
40 for i, entry in enumerate(output):
41 if isinstance(entry, float) or isinstance(entry, int):
42 list_final += [int(entry)]
43 elif isinstance(entry, str):
44 list_final += [int(entry.replace("(", "").replace(")", "").replace("@", ""))]
45 else:
46 raise ValueError("Every entry must be a string, float, or int")
47 assert isinstance(list_final[i], int)
48 return list_final
49 else:
50 raise ValueError("`output` must be a string or list.")
51
52
53 class Keithley2750(SCPIMixin, Instrument):
54 """ Represents the Keithley2750 multimeter/switch system and provides a high-level interface for
55 interacting with the instrument.
56 """
57
58 closed_channels = Instrument.measurement(":ROUTe:CLOSe?",
59 "Reads the list of closed channels",
60 get_process=clean_closed_channels)
61
62 def __init__(self, adapter, name="Keithley 2750 Multimeter/Switch System", **kwargs):
63 super().__init__(
64 adapter, name, **kwargs
65 )
66
67 def open(self, channel):
68 """ Opens (disconnects) the specified channel.
69
70 :param int channel: 3-digit number for the channel
71 :return: None
72 """
73 self.write(f":ROUTe:MULTiple:OPEN (@{channel})")
74
75 def close(self, channel):
76 """ Closes (connects) the specified channel.
77
78 :param int channel: 3-digit number for the channel
79 :return: None
80 """
81 # Note: if `MULTiple` is omitted, then the specified channel will close,
82 # but all other channels will open.
83 self.write(f":ROUTe:MULTiple:CLOSe (@{channel})")
84
85 def open_all(self):
86 """ Opens (disconnects) all the channels on the switch matrix.
87
88 :return: None
89 """
90 self.write(":ROUTe:OPEN:ALL")