Debian Codegraph @

pymeasure/instruments/srs/sg380.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, SCPIUnknownMixin
26 from pymeasure.instruments.validators import truncated_range
27
28
29 class SG380(SCPIUnknownMixin, Instrument):
30
31 MOD_TYPES_VALUES = ['AM', 'FM', 'PM', 'SWEEP', 'PULSE', 'BLANK', 'IQ']
32
33 MOD_FUNCTIONS = ['SINE', 'RAMP', 'TRIANGLE', 'SQUARE', 'NOISE', 'EXTERNAL']
34
35 MIN_RF = 0.0
36
37 MAX_RF = 4E9
38
39 # TODO: restrict modulation depth to allowed values (depending on
40 # frequency)
41 fm_dev = Instrument.control(
42 "FDEV?", "FDEV%.6f",
43 """ A floating point property that represents the modulation frequency
44 deviation in Hz. This property can be set. """
45 )
46
47 rate = Instrument.control(
48 "RATE?", "RATE%.6f",
49 """ A floating point property that represents the modulation rate
50 in Hz. This property can be set. """
51 )
52
53 def __init__(self, adapter, name="Stanford Research Systems SG380 RF Signal Generator",
54 **kwargs):
55 super().__init__(
56 adapter,
57 name,
58 **kwargs
59 )
60
61 @property
62 def has_doubler(self):
63 """Gets the modulation type"""
64 return bool(self.ask("OPTN? 2"))
65
66 @property
67 def has_IQ(self):
68 """Gets the modulation type"""
69 return bool(self.ask("OPTN? 3"))
70
71 @property
72 def frequency(self):
73 """Gets RF frequency"""
74 return float(self.ask("FREQ?"))
75
76 @frequency.setter
77 def frequency(self, frequency):
78 """Defines RF frequency"""
79 if self.has_doubler:
80 truncated_range(frequency, (SG380.MIN_RF, 2 * SG380.MAX_RF))
81 else:
82 truncated_range(frequency, (SG380.MIN_RF, SG380.MAX_RF))
83 self.write("FREQ%.6f" % frequency)
84
85 @property
86 def mod_type(self):
87 """Gets the modulation type"""
88 return SG380.MOD_TYPES_VALUES[int(self.ask("TYPE?"))]
89
90 @mod_type.setter
91 def mod_type(self, type_):
92 """Defines the modulation type"""
93 if type_ not in SG380.MOD_TYPES_VALUES:
94 raise RuntimeError('Undefined modulation type')
95 elif (type_ == 'IQ') and not self.has_IQ:
96 raise RuntimeError('IQ option not installed')
97 else:
98 index = SG380.MOD_TYPES_VALUES.index(type_)
99 self.write("TYPE%d" % index)
100
101 @property
102 def mod_function(self):
103 """Gets the modulation function"""
104 return SG380.MOD_FUNCTIONS[int(self.ask("MFNC?"))]
105
106 @mod_function.setter
107 def mod_func(self, function):
108 """Defines the modulation function"""
109 if function not in SG380.MOD_FUNCTIONS:
110 index = 1
111 else:
112 index = SG380.MOD_FUNCTIONS.index(function)
113 self.write("MFNC%d" % index)