mpylab 0.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. mpylab/LICENSE +25 -0
  2. mpylab/__init__.py +1 -0
  3. mpylab/device/Meta_ui.py +304 -0
  4. mpylab/device/__init__.py +1 -0
  5. mpylab/device/amp_ar_25s1g4.py +96 -0
  6. mpylab/device/amp_blma_1018_100.py +154 -0
  7. mpylab/device/amp_blwa_0810_100.py +111 -0
  8. mpylab/device/amp_cba_1g_030d.py +100 -0
  9. mpylab/device/amp_ifi_smx25.py +120 -0
  10. mpylab/device/amplifier.py +149 -0
  11. mpylab/device/device.py +2762 -0
  12. mpylab/device/driver.py +313 -0
  13. mpylab/device/driver_new.py +270 -0
  14. mpylab/device/fieldprobe.py +132 -0
  15. mpylab/device/fieldprobe_ui.py +90 -0
  16. mpylab/device/mc_teseq_stirrer.py +474 -0
  17. mpylab/device/motorcontroller.py +72 -0
  18. mpylab/device/mpy_exceptions.py +53 -0
  19. mpylab/device/networkanalyzer.py +533 -0
  20. mpylab/device/networkanalyzer_ui.py +139 -0
  21. mpylab/device/nport.py +169 -0
  22. mpylab/device/nw_rs_zlv.py +921 -0
  23. mpylab/device/pm_gt_8540c.py +321 -0
  24. mpylab/device/pm_lumiloop_lspm.py +426 -0
  25. mpylab/device/pm_rs_nrp.py +367 -0
  26. mpylab/device/pm_rxatt.py +1189 -0
  27. mpylab/device/pmini.ini +25 -0
  28. mpylab/device/powermeter.py +290 -0
  29. mpylab/device/powermeter2c.py +86 -0
  30. mpylab/device/powermeter_ui.py +118 -0
  31. mpylab/device/prb_ar_fm7004.py +145 -0
  32. mpylab/device/prb_lumiloop_lsprobe.py +460 -0
  33. mpylab/device/prb_pmm_ep601.py +221 -0
  34. mpylab/device/r_types.py +272 -0
  35. mpylab/device/sg_gt_12000a.py +180 -0
  36. mpylab/device/sg_rs_smb100a.py +215 -0
  37. mpylab/device/sg_rs_smc100a.py +251 -0
  38. mpylab/device/sg_rs_smf100a.py +272 -0
  39. mpylab/device/sg_rs_smr.py +144 -0
  40. mpylab/device/sg_rs_swm.py +121 -0
  41. mpylab/device/signalgenerator.py +253 -0
  42. mpylab/device/signalgenerator_ui.py +212 -0
  43. mpylab/device/sp_rs_zlv-6.py +566 -0
  44. mpylab/device/spectrumanalyzer.py +378 -0
  45. mpylab/device/spectrumanalyzer_ui.py +366 -0
  46. mpylab/device/switch.py +25 -0
  47. mpylab/device/tools.py +1043 -0
  48. mpylab/device/validators.py +283 -0
  49. mpylab/env/Measure.py +586 -0
  50. mpylab/env/__init__.py +1 -0
  51. mpylab/env/custom.py +27 -0
  52. mpylab/env/msc/ImmunityThreshold.py +229 -0
  53. mpylab/env/msc/MSC.py +3686 -0
  54. mpylab/env/msc/__init__.py +1 -0
  55. mpylab/env/tem/TEMCell.py +2079 -0
  56. mpylab/env/tem/__init__.py +1 -0
  57. mpylab/env/univers/AmplifierTest.py +576 -0
  58. mpylab/env/univers/__init__.py +1 -0
  59. mpylab/tools/Configuration.py +96 -0
  60. mpylab/tools/PControler.py +128 -0
  61. mpylab/tools/__init__.py +1 -0
  62. mpylab/tools/aunits.py +10 -0
  63. mpylab/tools/calling.py +74 -0
  64. mpylab/tools/correlation.py +96 -0
  65. mpylab/tools/dataparser.py +306 -0
  66. mpylab/tools/directivity.py +43 -0
  67. mpylab/tools/distributions.py +62 -0
  68. mpylab/tools/dot.g +141 -0
  69. mpylab/tools/dot.py +392 -0
  70. mpylab/tools/get_char.py +52 -0
  71. mpylab/tools/interpol.py +172 -0
  72. mpylab/tools/kbhit.py +41 -0
  73. mpylab/tools/level_control.py +175 -0
  74. mpylab/tools/levenshtein.py +103 -0
  75. mpylab/tools/log_freq.py +15 -0
  76. mpylab/tools/mgraph.py +1114 -0
  77. mpylab/tools/plyparser.py +63 -0
  78. mpylab/tools/plyparser_DatFile_parsetab.py +45 -0
  79. mpylab/tools/sin_fit.py +22 -0
  80. mpylab/tools/spacing.py +149 -0
  81. mpylab/tools/umd_types.py +103 -0
  82. mpylab/tools/uncertain.py +77 -0
  83. mpylab/tools/unixcrt.py +111 -0
  84. mpylab/tools/util.py +563 -0
  85. mpylab/tools/yappsrt.py +322 -0
  86. mpylab-0.9.dist-info/METADATA +34 -0
  87. mpylab-0.9.dist-info/RECORD +89 -0
  88. mpylab-0.9.dist-info/WHEEL +4 -0
  89. mpylab-0.9.dist-info/licenses/LICENSE +26 -0
mpylab/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ This module is free software: you can redistribute it and/or modify
2
+ it under the terms of the GNU General Public License as published by
3
+ the Free Software Foundation, either version 3 of the License, or
4
+ (at your option) any later version.
5
+
6
+ This module is distributed in the hope that it will be useful,
7
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
8
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9
+ GNU General Public License for more details.
10
+
11
+ You should have received a copy of the GNU General Public License
12
+ along with this module. If not, see <http://www.gnu.org/licenses/>.
13
+
14
+ Dieses Modul ist Freie Software: Sie können es unter den Bedingungen
15
+ der GNU General Public License, wie von der Free Software Foundation,
16
+ Version 3 der Lizenz oder (nach Ihrer Wahl) jeder neueren
17
+ veröffentlichten Version, weiter verteilen und/oder modifizieren.
18
+
19
+ Dieses Modul wird in der Hoffnung bereitgestellt, dass es nützlich sein wird, jedoch
20
+ OHNE JEDE GEWÄHR,; sogar ohne die implizite
21
+ Gewähr der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
22
+ Siehe die GNU General Public License für weitere Einzelheiten.
23
+
24
+ Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
25
+ Modul erhalten haben. Wenn nicht, siehe <https://www.gnu.org/licenses/>.
mpylab/__init__.py ADDED
@@ -0,0 +1 @@
1
+ __version__ = "0.9"
@@ -0,0 +1,304 @@
1
+ # -*- coding: utf-8 -*-
2
+ """This is :mod:`mpylab.device.Metaui`: Metaclass to Build a standard GUI from the _setgetlist.
3
+
4
+ :author: Christian Albrecht, Hans Georg Krauthaeuser
5
+ :copyright: All rights reserved
6
+ :license: no licence yet
7
+ """
8
+
9
+ import traits.api as tapi
10
+ from traits.etsconfig.api import ETSConfig
11
+ from traits.has_traits import MetaHasTraits
12
+
13
+ ETSConfig.toolkit = "wx"
14
+ import traitsui.api as tuiapi
15
+ import traitsui.menu as tuim
16
+ import io
17
+ import re
18
+ import inspect
19
+
20
+
21
+ def erzeugeFired_Methode_mit_Rfunction(command, rfunction, param_list):
22
+ """
23
+ Functionfactory zum erzeugen von Traits-fired Funktionen.
24
+ """
25
+
26
+ def Methode_fired(self):
27
+ setattr(self, rfunction.upper(), str(eval('self.dv.%s(%s)' % (command, ", ".join(param_list)))[1]))
28
+
29
+ return Methode_fired
30
+
31
+
32
+ def erzeugeFired_Methode(name, param_list):
33
+ """
34
+ Functionfactory zum erzeugen von Traits-fired Funktionen.
35
+ """
36
+
37
+ def Methode_fired(self):
38
+ setattr(self, name.upper(), str(eval('self.dv.%s(%s)' % (name, ", ".join(param_list)))[1]))
39
+
40
+ return Methode_fired
41
+
42
+
43
+ def _Init_fired(self):
44
+ """
45
+ Standard init_fired Funktion.
46
+ """
47
+ ini = io.StringIO(self.INI)
48
+ self.dv.Init(ini)
49
+
50
+ # Alle Get Funktionen einmal aufrufen und so die Anzeige mit aktuellen Werten belegen.
51
+ for item in self.mainEntries:
52
+ m = re.match(r'^[Gg]et.*$', item)
53
+ if m:
54
+ getattr(self, "_%s_fired" % item)()
55
+
56
+
57
+ def Erzeuge_TapiVar(typ):
58
+ """
59
+ Hilfsfunktion zum erstellen von Traits-Variablen.
60
+ """
61
+ if typ == float:
62
+ return tapi.Float()
63
+ elif typ == int:
64
+ return tapi.Int()
65
+ else:
66
+ return tapi.Str()
67
+
68
+
69
+ class Metaui(MetaHasTraits):
70
+ """
71
+ Diese Metaklasse ermöglicht das einfache Erstellen von Guis für das Testen eines Drivers.
72
+
73
+ Sie baut für alle im _commands- und _cmds-Dict vorhanden Commands und Functions passende Buttons und
74
+ Eingabefelder und nimmt so einem viel Schreibarbeit ab.
75
+
76
+ Es werden für alles in _commands und _cmds definiert Kommandos Buttons und Felder erstellt. Sind in dem cmds-Dict mehr
77
+ Kommandos definiert als in _commands, so werden auch für diese Buttons gebaut. Der Grund für dieses Vorgehen liegt in der
78
+ Tatsache, dass diese GUI zum testen der Klasse gedacht ist und somit alle definierten Kommandso abgebildet werden sollen.
79
+ Sind in _commands Kommandos aufgeführt die nicht in der konkreten Dirver-Klasse vorhanden sind, so wird eine Methode
80
+ erstellt welche einen NotImplementedError wirft.
81
+
82
+
83
+
84
+ Zu jeder Driver-Superklasse sollte ein UI-Superklasse existieren in der zusätzliche Taps definiert werden
85
+ die für alle von ihr abgeleiteten Driverklassen gleich sein sollen.
86
+ Damit die Metaklasse einwandfrei arbeiten kann, dürfen in der Superklasse nur
87
+ sogenannte tuiapi.Group (das sind Taps) erstellt werden. Diese müssen wiederrum in einem Dict
88
+ mit dem Namen "GROUPS" gespeichert werden. Wobei folgende Konvention einzuhalten ist::
89
+
90
+ GROUPS={'Name des Taps' : tuiapi.Group(...)}
91
+
92
+ Als Beispiele siehe: :mod:`mpylab.device.networkanalyer_ui`
93
+
94
+
95
+
96
+ Weiterhin muss eine UI-Klasse für jede konkrete Driver-Implementierung erstellt werden, diese muss von
97
+ der UI-Superklasse abgeleitet sein. In dieser muss die Meta_ui als Metaklasse angegeben werden, weiterhin
98
+ sind folgende speziall Variablen nötig:
99
+
100
+ **__driverclass__= :** Verweis auf eine konkrete Klasse einer Driver-Implementierung. ACHTUNG!! nur ein Verweis auf die Klasse,
101
+ keine Instanz der Klasse.
102
+
103
+ **__super_driverclass__=**: Verweis auf die Superklasse eines Driver. ACHTUNG!! nur ein Verweis auf die Klasse,
104
+ keine Instanz der Klasse.
105
+
106
+ Aus diesen Varialben holt sich die Metaklase das _commands-Dict und _cmds-Dict.
107
+
108
+ Als Beispiel siehe: :class:`mpylab.device.nw_rs_zlv.UI`
109
+
110
+ .. rubric:: Methods:
111
+ """
112
+
113
+ # def __init__(cls, eins, zwei, drei):
114
+ # print "init %s \n\n %s \n\n %s"%(eins,zwei,drei)
115
+
116
+ def __new__(cls, class_name, bases, class_dict):
117
+
118
+ class_dict.update({'_Init_fired': _Init_fired})
119
+
120
+ driverclass = class_dict.get("__driverclass__")
121
+ super_driverclass = class_dict.get('__super_driverclass__')
122
+
123
+ tabs = 'INI_grp'
124
+ INI_grp = tuiapi.Group(
125
+ tuiapi.Item('INI', style='custom', springy=True, width=500, height=200, show_label=False),
126
+ tuiapi.Item('Init', show_label=False),
127
+ label='Ini')
128
+
129
+ # ********************
130
+ # _cmds abarbeiten
131
+ # ********************
132
+
133
+ _cmds = driverclass._cmds
134
+ mainEntries = []
135
+ items_Map = {}
136
+
137
+ for command_name, command in list(_cmds.items()):
138
+ items = ""
139
+ if command_name in class_dict['_ignore']:
140
+ continue
141
+ if command_name in mainEntries:
142
+ continue
143
+
144
+ mainEntries.append(command_name)
145
+
146
+ items = "%s tuiapi.Group(" % (items)
147
+ items = "%s tuiapi.Item('%s',show_label=False,width=100)," % (items, command_name)
148
+ class_dict[command_name] = tapi.Button(command_name)
149
+
150
+ if command.Rfunction():
151
+ items = "%s tuiapi.Item('%s',show_label=False,width=100)," % (items, command.Rfunction())
152
+ items = "%s tuiapi.Item('%s',label='Wert',style='readonly',width=70)," % (
153
+ items, command.Rfunction().upper())
154
+
155
+ class_dict[command.Rfunction().upper()] = Erzeuge_TapiVar(str)
156
+ class_dict[command.Rfunction()] = tapi.Button(command.Rfunction())
157
+
158
+ if command.Rfunction() not in mainEntries:
159
+ mainEntries.append(command.Rfunction())
160
+
161
+ if command.Rfunction() in list(items_Map.keys()):
162
+ del items_Map[command.Rfunction()]
163
+ else:
164
+ items = "%s tuiapi.Item('%s',label='%s',style='readonly',width=70)," % (
165
+ items, command_name.upper(), 'Wert'.rjust(38))
166
+ class_dict[command_name.upper()] = Erzeuge_TapiVar(str)
167
+
168
+ param_list = []
169
+ for param_name in command.getParameterTuple():
170
+ param = command.getParameter()[param_name]
171
+ if param.isClass_attr():
172
+ continue
173
+
174
+ if hasattr(driverclass, command_name):
175
+ if param_name not in inspect.getfullargspec(getattr(driverclass, command_name))[0]:
176
+ continue
177
+
178
+ items = "%s tuiapi.Item('param_%s_%s',label='%s',width=60)," % (items,
179
+ command_name,
180
+ param_name.upper(),
181
+ param_name)
182
+ class_dict['param_%s_%s' % (command_name, param_name.upper())] = Erzeuge_TapiVar(param.Getptype())
183
+ param_list.append('self.param_%s_%s' % (command_name, param_name.upper()))
184
+
185
+ if command.Rfunction():
186
+ class_dict["_%s_fired" % command_name] = erzeugeFired_Methode_mit_Rfunction(command_name,
187
+ command.Rfunction(),
188
+ param_list)
189
+ class_dict["_%s_fired" % command.Rfunction()] = erzeugeFired_Methode(command.Rfunction(), [])
190
+
191
+ else:
192
+ class_dict["_%s_fired" % command_name] = erzeugeFired_Methode(command_name, param_list)
193
+
194
+ items = "%s orientation='horizontal')" % (items)
195
+ items_Map[command_name] = items
196
+
197
+ class_dict.update({'mainEntries': mainEntries})
198
+
199
+ item_List = list(items_Map.values())
200
+ item_List = [item_List[i:i + 16] for i in range(0, len(item_List), 16)]
201
+
202
+ tabs_list_index = 0
203
+ tabs_list = []
204
+
205
+ for item in item_List:
206
+ tabs_list.append(tuiapi.Group(eval(", ".join(item)), label='Main_%d' % tabs_list_index))
207
+ tabs = tabs + ", tabs_list[%d]" % tabs_list_index
208
+ tabs_list_index = tabs_list_index + 1
209
+
210
+ # *******************
211
+ # commands abarbeiten
212
+ # *******************
213
+
214
+ notIEntries = []
215
+ items_Map = {}
216
+
217
+ for command_name, item in list(super_driverclass._commands.items()):
218
+ items = ""
219
+ if (command_name in mainEntries) or (command_name in notIEntries):
220
+ continue
221
+ if command_name in class_dict['_ignore']:
222
+ continue
223
+
224
+ if item['parameter']:
225
+ para_command = item['parameter']
226
+ if isinstance(para_command, str):
227
+ para_command = (para_command,)
228
+
229
+ # Testen ob die Methode direkt, also nicht über _cmds, implementiert wurde:
230
+ # Wird die Methode in _commands angegeben, aber nicht implementiert wurde,
231
+ # Erzeug die Meta Klasse eine Methode die einen NotImplementedError wirft
232
+ driver_ins = driverclass()
233
+ try:
234
+ p = ""
235
+ if item['parameter']:
236
+ for param_name in para_command:
237
+ p = p + "'',"
238
+ eval('driverclass.%s(driver_ins,%s)' % (command_name, p))
239
+ except NotImplementedError:
240
+ pass
241
+ else:
242
+ driver_ins.__del__()
243
+ continue
244
+
245
+ driver_ins.__del__()
246
+
247
+ notIEntries.append(command_name)
248
+
249
+ items = "%s tuiapi.Group(" % (items)
250
+ items = "%s tuiapi.Item('%s',show_label=False,width=100)," % (items, command_name)
251
+ class_dict[command_name] = tapi.Button(command_name)
252
+
253
+ items = "%s tuiapi.Item('%s',label='%s',style='readonly',width=70)," % (items, command_name.upper(), 'Wert')
254
+ class_dict[command_name.upper()] = Erzeuge_TapiVar(str)
255
+
256
+ param_list = []
257
+
258
+ if item['parameter']:
259
+ for param_name in para_command:
260
+ items = "%s tuiapi.Item('param_%s_%s',label='%s',width=60)," % (
261
+ items, command_name, param_name.upper(), param_name)
262
+ class_dict['param_%s_%s' % (command_name, param_name.upper())] = Erzeuge_TapiVar(str)
263
+ param_list.append('self.param_%s_%s' % (command_name, param_name.upper()))
264
+
265
+ class_dict["_%s_fired" % command_name] = erzeugeFired_Methode(command_name, param_list)
266
+
267
+ items = "%s orientation='horizontal')" % (items)
268
+ items_Map[command_name] = items
269
+
270
+ item_List = list(items_Map.values())
271
+ item_List = [item_List[i:i + 16] for i in range(0, len(item_List), 16)]
272
+
273
+ for item in item_List:
274
+ tabs_list.append(tuiapi.Group(eval(", ".join(item)), label='NotImp_%d' % tabs_list_index))
275
+ tabs = tabs + ", tabs_list[%d]" % tabs_list_index
276
+ tabs_list_index = tabs_list_index + 1
277
+
278
+ # **********************
279
+ # In den UI Klassen definiert Groups holen:
280
+ # ************************
281
+
282
+ for i in class_dict:
283
+ if type(class_dict.get(i)) == tuiapi.Group:
284
+ tabs = '%s,class_dict.get("%s")' % (tabs, i)
285
+
286
+ i = 0
287
+ for b in bases:
288
+ for n, v in list(b.GROUPS.items()):
289
+ if type(v) == tuiapi.Group:
290
+ tabs = '%s,bases[%d].GROUPS["%s"]' % (tabs, i, n)
291
+ i = i + 1
292
+
293
+ # *************
294
+ # Fenster zusammen bauen:
295
+ # ***************
296
+
297
+ tabs = "tuiapi.Group(%s, layout='tabbed')" % tabs
298
+
299
+ class_dict.update(
300
+ {'traits_view': tuiapi.View(eval(tabs), title="Spectrumanalyer", buttons=[tuim.CancelButton])})
301
+
302
+ # print "Meta %s \n\n bases\n %s \n\n dict \n %s"%(class_name,str(bases),str(class_dict))
303
+
304
+ return MetaHasTraits.__new__(cls, class_name, bases, class_dict)
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,96 @@
1
+ # -*- coding: utf-8 -*-
2
+ from simpleeval import simple_eval
3
+
4
+ from mpylab.device.amplifier import AMPLIFIER as AMP
5
+
6
+
7
+ class AMPLIFIER(AMP):
8
+ conftmpl = AMP.conftmpl
9
+ conftmpl['init_value']['gpib'] = int
10
+
11
+ def __init__(self):
12
+ AMP.__init__(self)
13
+ self._cmds = {'POn': [("P1", None)],
14
+ 'POff': [("P0", None)],
15
+ 'Operate': [("G4095", None)],
16
+ 'Standby': [("G0000", None)],
17
+ 'GetDescription': [('*IDN?', r'(?P<IDN>.*)')]}
18
+ self.term_chars = '\r\n'
19
+ self.error = None
20
+
21
+ def Init(self, ini=None, channel=None):
22
+ self.error = AMP.Init(self, ini, channel)
23
+ self.POn()
24
+ self.Operate()
25
+ return self.error
26
+
27
+
28
+ def main():
29
+ import sys
30
+ import io
31
+
32
+ from mpylab.tools.util import format_block
33
+ import scuq
34
+
35
+ try:
36
+ ini = sys.argv[1]
37
+ except IndexError:
38
+ ini = format_block("""
39
+ [description]
40
+ DESCRIPTION = 25s1g4
41
+ TYPE = AMPLIFIER
42
+ VENDOR = AR
43
+ SERIALNR =
44
+ DEVICEID =
45
+ DRIVER =
46
+
47
+ [INIT_VALUE]
48
+ FSTART = 800e6
49
+ FSTOP = 4.2e9
50
+ FSTEP = 0.0
51
+ NR_OF_CHANNELS = 2
52
+ GPIB = 1
53
+ VIRTUAL = 0
54
+
55
+ [CHANNEL_1]
56
+ NAME = S21
57
+ UNIT = dB
58
+ INTERPOLATION = LOG
59
+ FILE = io.StringIO(format_block('''
60
+ FUNIT: Hz
61
+ UNIT: dB
62
+ ABSERROR: 0.0
63
+ 800e6 45
64
+ 4.2e9 45
65
+ '''))
66
+ [CHANNEL_2]
67
+ NAME = MAXIN
68
+ UNIT = dBm
69
+ INTERPOLATION = LOG
70
+ FILE = io.StringIO(format_block('''
71
+ FUNIT: Hz
72
+ UNIT: dBm
73
+ ABSERROR: 0.0
74
+ 800e6 0
75
+ 4.2e9 0
76
+ '''))
77
+ """)
78
+ ini = io.StringIO(ini)
79
+
80
+ amp = AMPLIFIER()
81
+ err = amp.Init(ini)
82
+ print(amp.GetDescription())
83
+ ctx = scuq.ucomponents.Context()
84
+ while True:
85
+ freq = float(simple_eval(input("Freq / Hz: ")))
86
+ if freq < 0:
87
+ break
88
+ amp.SetFreq(freq)
89
+ err, uq = amp.GetData(what='S21')
90
+ val, unc, unit = ctx.value_uncertainty_unit(uq)
91
+ print((freq, uq, val, unc, unit))
92
+ err = amp.Quit()
93
+
94
+
95
+ if __name__ == '__main__':
96
+ main()
@@ -0,0 +1,154 @@
1
+ # -*- coding: utf-8 -*-
2
+ import pyvisa
3
+ import time
4
+ from mpylab.device.amplifier import AMPLIFIER as AMP
5
+
6
+
7
+ class AMPLIFIER(AMP):
8
+ conftmpl = AMP.conftmpl
9
+ conftmpl['init_value']['gpib'] = int
10
+
11
+ def __init__(self):
12
+ AMP.__init__(self)
13
+ self.operating = False
14
+ self._cmds = {'POn': [("AMP_OFF", None)],
15
+ 'POff': [("AMP_OFF", None)],
16
+ 'Operate': [("AMP_ON", None)],
17
+ 'Standby': [("AMP_OFF", None)],
18
+ 'GetDescription': [('*IDN?', r'(?P<IDN>.*)')]}
19
+ self.term_chars = '\n'
20
+ self.error = None
21
+
22
+ def Init(self, ini=None, channel=None):
23
+ self.error = AMP.Init(self, ini, channel)
24
+ # self.POn()
25
+ self.Standby()
26
+ # time.sleep(2)
27
+ return self.error
28
+
29
+ def _query(self, cmd, N=5, sleep=0.2):
30
+ ans = None
31
+ for _ in range(N):
32
+ try:
33
+ ans = self.dev.query(cmd)
34
+ break # no exception
35
+ except pyvisa.VisaIOError:
36
+ time.sleep(sleep)
37
+ continue # try again
38
+ else:
39
+ raise # re raise exception
40
+ return ans
41
+
42
+ def _wait(self, state=False):
43
+ while True:
44
+ ans = self._query('AMP?')
45
+ rstate = (ans == 'AMP_ON')
46
+ if state == rstate:
47
+ break
48
+ time.sleep(0.1)
49
+
50
+ def SetFreq(self, freq):
51
+ self.error = 0
52
+ if (1e9 <= freq <= 18e9) and (not self.operating):
53
+ self.Operate()
54
+ time.sleep(2)
55
+ self.operating = True
56
+ elif (not 1e9 <= freq <= 18e9) and self.operating:
57
+ self.Standby()
58
+ self.operating = False
59
+ return self.error, freq
60
+
61
+ swstat = self._query('SW01?')
62
+ assert swstat.startswith('SW01_')
63
+ swstat = int(swstat[-1])
64
+ if freq <= 2e9:
65
+ sw = 1
66
+ elif freq <= 6e9:
67
+ sw = 2
68
+ else:
69
+ sw = 3
70
+
71
+ if sw != swstat:
72
+ self.Standby()
73
+ self._wait(False)
74
+ self.write('SW01_%d' % sw)
75
+ self.Operate()
76
+ self._wait(True)
77
+ time.sleep(2)
78
+ self.error, freq = AMP.SetFreq(self, freq)
79
+ time.sleep(0.2)
80
+ return self.error, freq
81
+
82
+
83
+ def main():
84
+ import sys
85
+ import io
86
+
87
+ from mpylab.tools.util import format_block
88
+ import scuq
89
+
90
+ try:
91
+ ini = sys.argv[1]
92
+ except IndexError:
93
+ ini = format_block("""
94
+ [description]
95
+ DESCRIPTION = BLMA1018 100
96
+ TYPE = AMPLIFIER
97
+ VENDOR = Bonn
98
+ SERIALNR =
99
+ DEVICEID =
100
+ DRIVER =
101
+
102
+ [INIT_VALUE]
103
+ FSTART = 1e9
104
+ FSTOP = 18e9
105
+ FSTEP = 0.0
106
+ NR_OF_CHANNELS = 2
107
+ GPIB = 7
108
+ VIRTUAL = 0
109
+
110
+ [CHANNEL_1]
111
+ NAME = S21
112
+ UNIT = dB
113
+ INTERPOLATION = LOG
114
+ FILE = io.StringIO(format_block('''
115
+ FUNIT: Hz
116
+ UNIT: dB
117
+ ABSERROR: 0.5
118
+ 1e9 50
119
+ 2e9 50
120
+ 2.001e0 44.8
121
+ 6e9 44.8
122
+ 6.001e9 43
123
+ 18e9 43
124
+ '''))
125
+ [CHANNEL_2]
126
+ NAME = MAXIN
127
+ UNIT = dBm
128
+ INTERPOLATION = LOG
129
+ FILE = io.StringIO(format_block('''
130
+ FUNIT: Hz
131
+ UNIT: dBm
132
+ ABSERROR: 0.0
133
+ 1e9 -5
134
+ 18e9 -5
135
+ '''))
136
+ """)
137
+ ini = io.StringIO(ini)
138
+
139
+ amp = AMPLIFIER()
140
+ err = amp.Init(ini)
141
+ ctx = scuq.ucomponents.Context()
142
+ while True:
143
+ freq = float(eval(input("Freq / Hz: ")))
144
+ if freq < 0:
145
+ break
146
+ amp.SetFreq(freq)
147
+ err, uq = amp.GetData(what='S21')
148
+ val, unc, unit = ctx.value_uncertainty_unit(uq)
149
+ print((freq, uq, val, unc, unit))
150
+ amp.POff()
151
+
152
+
153
+ if __name__ == '__main__':
154
+ main()
@@ -0,0 +1,111 @@
1
+ # -*- coding: utf-8 -*-
2
+ import time
3
+
4
+ from mpylab.device.amplifier import AMPLIFIER as AMP
5
+
6
+
7
+ class AMPLIFIER(AMP):
8
+ conftmpl = AMP.conftmpl
9
+ conftmpl['init_value']['gpib'] = int
10
+
11
+ def __init__(self):
12
+ AMP.__init__(self)
13
+ self.operating = False
14
+ self._cmds = {'POn': [("AMP_OFF", None)],
15
+ 'POff': [("AMP_OFF", None)],
16
+ 'Operate': [("AMP_ON", None)],
17
+ 'Standby': [("AMP_OFF", None)],
18
+ 'GetDescription': [('*IDN?', r'(?P<IDN>.*)')]}
19
+ self.term_chars = '\n'
20
+
21
+ def Init(self, ini=None, channel=None):
22
+ self.error = AMP.Init(self, ini, channel)
23
+ # self.POn()
24
+ self.Standby()
25
+ # time.sleep(2)
26
+ return self.error
27
+
28
+ def SetFreq(self, freq):
29
+ self.error = 0
30
+
31
+ if (80e6 <= freq <= 1e9) and (not self.operating):
32
+ self.Operate()
33
+ time.sleep(2)
34
+ self.operating = True
35
+ elif (not 80e6 <= freq <= 1e9) and self.operating:
36
+ self.Standby()
37
+ self.operating = False
38
+ return self.error, freq
39
+
40
+ self.error, freq = AMP.SetFreq(self, freq)
41
+ time.sleep(0.2)
42
+ return self.error, freq
43
+
44
+
45
+ def main():
46
+ import sys
47
+ import io
48
+
49
+ from mpylab.tools.util import format_block
50
+ import scuq
51
+
52
+ try:
53
+ ini = sys.argv[1]
54
+ except IndexError:
55
+ ini = format_block("""
56
+ [description]
57
+ DESCRIPTION = BLMA0810 100
58
+ TYPE = AMPLIFIER
59
+ VENDOR = Bonn
60
+ SERIALNR =
61
+ DEVICEID =
62
+ DRIVER =
63
+
64
+ [INIT_VALUE]
65
+ FSTART = 80e6
66
+ FSTOP = 1e9
67
+ FSTEP = 0.0
68
+ NR_OF_CHANNELS = 2
69
+ GPIB = 9
70
+ VIRTUAL = 0
71
+
72
+ [CHANNEL_1]
73
+ NAME = S21
74
+ UNIT = dB
75
+ INTERPOLATION = LOG
76
+ FILE = io.StringIO(format_block('''
77
+ FUNIT: Hz
78
+ UNIT: dB
79
+ ABSERROR: 0.5
80
+ 80e6 50
81
+ 1e9 50
82
+ '''))
83
+ [CHANNEL_2]
84
+ NAME = MAXIN
85
+ UNIT = dBm
86
+ INTERPOLATION = LOG
87
+ FILE = io.StringIO(format_block('''
88
+ FUNIT: Hz
89
+ UNIT: dBm
90
+ ABSERROR: 0.0
91
+ 80e6 -5
92
+ 1e9 -5
93
+ '''))
94
+ """)
95
+ ini = io.StringIO(ini)
96
+
97
+ amp = AMPLIFIER()
98
+ err = amp.Init(ini)
99
+ ctx = scuq.ucomponents.Context()
100
+ while True:
101
+ freq = float(eval(input("Freq / Hz: ")))
102
+ if freq < 0:
103
+ break
104
+ amp.SetFreq(freq)
105
+ err, uq = amp.GetData(what='S21')
106
+ val, unc, unit = ctx.value_uncertainty_unit(uq)
107
+ print((freq, uq, val, unc, unit))
108
+
109
+
110
+ if __name__ == '__main__':
111
+ main()