Debian Codegraph @

pymeasure/instruments/lakeshore/lakeshore425.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
26 from pymeasure.instruments.validators import strict_discrete_set, truncated_discrete_set
27
28 from time import sleep
29 import numpy as np
30
31
32 class LakeShore425(Instrument):
33 """ Represents the LakeShore 425 Gaussmeter and provides
34 a high-level interface for interacting with the instrument
35
36 To allow user access to the LakeShore 425 Gaussmeter in Linux,
37 create the file:
38 :code:`/etc/udev/rules.d/52-lakeshore425.rules`, with contents:
39
40 .. code-block:: none
41
42 SUBSYSTEMS=="usb",ATTRS{idVendor}=="1fb9",ATTRS{idProduct}=="0401",MODE="0666",SYMLINK+="lakeshore425"
43
44 Then reload the udev rules with:
45
46 .. code-block:: bash
47
48 sudo udevadm control --reload-rules
49 sudo udevadm trigger
50
51 The device will be accessible through :code:`/dev/lakeshore425`.
52 """
53
54 field = Instrument.measurement(
55 "RDGFIELD?",
56 """ Get the field in the current units """
57 )
58 unit = Instrument.control(
59 "UNIT?", "UNIT %d",
60 """ Control the units of the instrument,
61 which can take the values of G, T, Oe, or A/m. (str)""",
62 validator=strict_discrete_set,
63 values={'G': 1, 'T': 2, 'Oe': 3, 'A/m': 4},
64 map_values=True
65 )
66 range = Instrument.control(
67 "RANGE?", "RANGE %d",
68 """ Control the field range in
69 units of Gauss, which can take the values 35, 350, 3500, and
70 35,000 G. (float)""",
71 validator=truncated_discrete_set,
72 values={35: 1, 350: 2, 3500: 3, 35000: 4},
73 map_values=True
74 )
75
76 def __init__(self, adapter, name="LakeShore 425 Gaussmeter", **kwargs):
77 super().__init__(
78 adapter,
79 name,
80 asrl={'write_termination': "\n",
81 'read_termination': "\n", # from manual
82 'baud_rate': 57600,
83 'timeout': 500,
84 'parity': 1, # odd
85 'data_bits': 7
86 },
87 includeSCPI=False,
88 **kwargs
89 )
90
91 def auto_range(self):
92 """ Sets the field range to automatically adjust """
93 self.write("AUTO")
94
95 def dc_mode(self, wideband=True):
96 """ Sets up a steady-state (DC) measurement of the field """
97 if wideband:
98 self.mode = (1, 0, 1)
99 else:
100 self.mode = (1, 0, 2)
101
102 def ac_mode(self, wideband=True):
103 """ Sets up a measurement of an oscillating (AC) field """
104 if wideband:
105 self.mode = (2, 1, 1)
106 else:
107 self.mode = (2, 1, 2)
108
109 @property
110 def mode(self):
111 """Control the mode, filter, and bandwidth settings."""
112 return tuple(self.values("RDGMODE?"))
113
114 @mode.setter
115 def mode(self, value):
116 mode, filter, band = value
117 self.write("RDGMODE %d,%d,%d" % (mode, filter, band))
118
119 def zero_probe(self):
120 """ Initiates the zero field sequence to calibrate the probe """
121 self.write("ZPROBE")
122
123 def measure(self, points, has_aborted=lambda: False, delay=1e-3):
124 """Returns the mean and standard deviation of a given number
125 of points while blocking
126 """
127 data = np.zeros(points, dtype=np.float32)
128 for i in range(points):
129 if has_aborted():
130 break
131 data[i] = self.field
132 sleep(delay)
133 return data.mean(), data.std()