Debian Codegraph @

pymeasure/instruments/teledyne/teledyneT3AFG.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 import logging
26
27 from pymeasure.instruments import Instrument, Channel, SCPIMixin
28 from pymeasure.instruments.validators import strict_range, strict_discrete_set
29
30 log = logging.getLogger(__name__)
31 log.addHandler(logging.NullHandler())
32
33
34 def get_process_generator_search(keyword, unit, type):
35 """Generate a get_process method searching for keyword, stripping unit"""
36
37 def selector(values):
38 if keyword in values:
39 try:
40 return type(values[values.index(keyword) + 1].strip(unit))
41 except (ValueError, IndexError):
42 # Something went quite wrong if the keyword exists but the value doesn't
43 return None
44 else:
45 # Wrong wavetype for this keyword
46 return None
47
48 return selector
49
50
51 class SignalChannel(Channel):
52 output_enabled = Channel.control(
53 "C{ch}:OUTPut?",
54 "C{ch}:OUTPut %s",
55 """Control whether the channel output is enabled (boolean).""",
56 validator=strict_discrete_set,
57 map_values=True,
58 values={True: 'ON', False: 'OFF'},
59 # Replace ON and OFF with True and False in both get and set
60 get_process=lambda x: True if x[0].split(' ')[1] == 'ON' else False,
61 )
62
63 wavetype = Channel.control(
64 "C{ch}:BSWV?",
65 "C{ch}:BSWV WVTP,%s",
66 """Control the type of waveform to be output.
67 Options are: {'SINE', 'SQUARE', 'RAMP', 'PULSE', 'NOISE', 'ARB', 'DC', 'PRBS', 'IQ'}
68 """,
69 validator=strict_discrete_set,
70 values=['SINE', 'SQUARE', 'RAMP', 'PULSE', 'NOISE', 'ARB', 'DC', 'PRBS', 'IQ'],
71 get_process=lambda x: x[1],
72 )
73
74 frequency = Channel.control(
75 "C{ch}:BSWV?",
76 "C{ch}:BSWV FRQ,%g",
77 """Control the frequency of waveform to be output in Hertz.
78 Has no effect when WVTP is NOISE or DC.""",
79 validator=strict_range,
80 values=[0, 350e6],
81 get_process=get_process_generator_search('FRQ', 'HZ', float),
82 dynamic=True,
83 check_set_errors=True,
84 )
85
86 amplitude = Channel.control(
87 "C{ch}:BSWV?",
88 "C{ch}:BSWV AMP,%g",
89 """Control the amplitude of waveform to be output in volts peak-to-peak.
90 Has no effect when WVTP is NOISE or DC.
91 Max amplitude depends on offset, frequency, and load.
92 Amplitude is also limited by the channel max output amplitude.""",
93 validator=strict_range,
94 values=[-5, 5],
95 get_process=get_process_generator_search('AMP', 'V', float),
96 dynamic=True,
97 check_set_errors=True,
98 )
99
100 offset = Channel.control(
101 "C{ch}:BSWV?",
102 "C{ch}:BSWV OFST,%g",
103 """Control the offset of waveform to be output in volts.
104 Has no effect when WVTP is NOISE.
105 Max offset depends on amplitude, frequency, and load.
106 Offset is also limited by the channel max output amplitude.""",
107 validator=strict_range,
108 values=[-5, 5],
109 get_process=get_process_generator_search('OFST', 'V', float),
110 dynamic=True,
111 check_set_errors=True,
112 )
113
114 max_output_amplitude = Channel.control(
115 "C{ch}:BSWV?",
116 "C{ch}:BSWV MAX_OUTPUT_AMP,%g",
117 """Control the maximum output amplitude of the channel in volts peak to peak.""",
118 validator=strict_range,
119 values=[0, 20],
120 get_process=get_process_generator_search('MAX_OUTPUT_AMP', 'V', float),
121 dynamic=True,
122 )
123
124
125 class TeledyneT3AFG(SCPIMixin, Instrument):
126 """Represents the Teledyne T3AFG series of arbitrary waveform
127 generator interface for interacting with the instrument.
128
129 Initially targeting T3AFG80, some features may not be available on
130 lower end models and features from higher end models are not
131 included here yet.
132
133 Future improvements (help welcomed):
134
135 - Add other OUTPut related controls like Load and Polarity
136 - Add other Basic Waveform related controls like Period
137 - Add frequency ranges per model
138 - Add channel coupling control
139
140 .. code-block: python
141
142 # Example assumes Ethernet (TCPIP) interface
143 generator=TeledyneT3AFG('TCPIP0::xxx.xxx.xxx.xxx::pppp::SOCKET')
144 generator.reset()
145 generator.ch_1.wavetype='SINE'
146 generator.ch_1.amplitude=2
147 generator.ch_1.output_enabled=True
148 """
149
150 ch_1 = Instrument.ChannelCreator(SignalChannel, 1)
151
152 ch_2 = Instrument.ChannelCreator(SignalChannel, 2)
153
154 def __init__(self, adapter, name="Teledyne T3AFG", **kwargs):
155 super().__init__(
156 adapter,
157 name,
158 tcpip={'read_termination': '\n'},
159 **kwargs
160 )