Debian Codegraph @

pymeasure/instruments/fwbell/fwbell5080.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 from pymeasure.instruments.validators import strict_discrete_set
27 from time import sleep
28
29 import numpy as np
30
31
32 class FWBell5080(SCPIMixin, Instrument):
33 """ Represents the F.W. Bell 5080 Handheld Gaussmeter and
34 provides a high-level interface for interacting with the
35 instrument
36
37 :param port: The serial port of the instrument
38
39 .. code-block:: python
40
41 meter = FWBell5080('/dev/ttyUSB0') # Connects over serial port /dev/ttyUSB0 (Linux)
42
43 meter.units = 'gauss' # Sets the measurement units to Gauss
44 meter.range = 1 # Sets the range to 3 kG
45 print(meter.field) # Reads and prints a field measurement in G
46
47 fields = meter.fields(100) # Samples 100 field measurements
48 print(fields.mean(), fields.std()) # Prints the mean and standard deviation of the samples
49
50 """
51
52 def __init__(self, adapter, name="F.W. Bell 5080 Handheld Gaussmeter", **kwargs):
53 kwargs.setdefault('timeout', 500)
54 kwargs.setdefault('baudrate', 2400)
55 super().__init__(
56 adapter,
57 name,
58 **kwargs
59 )
60
61 field = Instrument.measurement(
62 ":MEASure:FLUX?",
63 """ Measure the field in the appropriate units (float).
64 """,
65 # Remove units
66 get_process=lambda v: float(v.replace('T', '').replace('G', '').replace('Am', ''))
67
68 )
69
70 UNITS = {
71 'gauss': 'DC:GAUSS', 'gauss ac': 'AC:GAUSS',
72 'tesla': 'DC:TESLA', 'tesla ac': 'AC:TESLA',
73 'amp-meter': 'DC:AM', 'amp-meter ac': 'AC:AM'
74 }
75
76 units = Instrument.control(
77 ":UNIT:FLUX?", ":UNIT:FLUX:%s",
78 """ Get the field units (str), which can take the
79 values: 'gauss', 'gauss ac', 'tesla', 'tesla ac', 'amp-meter', and
80 'amp-meter ac'. The AC versions configure the instrument to measure AC.
81 """,
82 validator=strict_discrete_set,
83 values=UNITS,
84 map_values=True
85 )
86
87 range = Instrument.control(
88 ":SENS:FLUX:RANG?", ":SENS:FLUX:RANG %d",
89 """ Control the maximum field range in the active units (int).
90 The range unit is dependent on the current units mode (gauss, tesla, amp-meter). Value
91 sets an equivalent range across units that increases in magnitude (1, 10, 100).
92
93 +--------+--------+---------+-----------+
94 | Value | gauss | tesla | amp-meter |
95 +--------+--------+---------+-----------+
96 | 0 | 300 G | 30 mT | 23.88 kAm |
97 +--------+--------+---------+-----------+
98 | 1 | 3 kG | 300 mT | 238.8 kAm |
99 +--------+--------+---------+-----------+
100 | 2 | 30 kG | 3 T | 2388 kAm |
101 +--------+--------+---------+-----------+
102 """,
103 validator=strict_discrete_set,
104 values=[0, 1, 2],
105 cast=int
106 )
107
108 def read(self):
109 """ Overwrites the :meth:`Instrument.read <pymeasure.instruments.Instrument.read>`
110 method to remove semicolons and replace spaces with colons.
111 """
112 # To set the unit mode to DC Tesla you need to write(':UNIT:FLUX:DC:TESLA')
113 # However the response from ask(':UNIT:FLUX?') is "DC TESLA", with no colon.
114 # We replace space with colon to preserve the mapping in UNITS.
115 # Semicolons may be appended to end of response from FW Bell 5080, and are removed
116 return super().read().replace(' ', ':').replace(';', '')
117
118 def reset(self):
119 """ Resets the instrument. """
120 self.clear()
121
122 def fields(self, samples=1):
123 """ Returns a numpy array of field samples for a given sample number.
124
125 :param samples: The number of samples to preform
126 """
127 if samples < 1:
128 raise Exception("F.W. Bell 5080 does not support samples less than 1.")
129 else:
130 data = [self.field for i in range(int(samples))]
131 return np.array(data, dtype=np.float64)
132
133 def auto_range(self):
134 """ Enables the auto range functionality. """
135 self.write(":SENS:FLUX:RANG:AUTO")
136 # Instrument needs a delay before next command
137 sleep(2)