Attachment 'getgpibdata.py'
Download 1 #! /usr/bin/env python
2 #
3 # getgpibdata.py
4 #
5 # This script will get data from an Agilent 4395A network analyzer
6 # and spits out the data into standard output.
7 # The output format is a space delimited list, each row representing a frequency point.
8 # The meanings of columns are:
9 #<Network analyzer mode>
10 # freq real imag
11 #<Spectrum analyzer mode>
12 # freq mag1 [mag2]
13 # mag2 is present only when the dual channel mode is active.
14 #
15 # Yoichi Aso Aug 26 2008
16
17 import re
18 import Gpib
19 device = Gpib.Gpib("ag4395a")
20
21 #Put the analyzer on hold
22 device.write("HOLD")
23
24 #Get the number of data points
25 device.write("POIN?")
26 numPoints = device.read(30)
27 numPoints = int(numPoints)
28
29 #Set the output format to ASCII
30 device.write("FORM4")
31
32 #Get the frequency points
33 device.write("OUTPSWPRM?")
34 freq = device.read(23*numPoints)
35
36 #Break the data into lists
37 freqList = re.findall(r'[-+.E0-9]+',freq)
38
39 #Check for the analyzer mode
40 device.write("NA?")
41 analyzerMode = int(device.read())
42
43 if analyzerMode == 1:
44 # It is the network analyzer mode
45 # In this mode, the data format is real,imag for each frequency point
46 #Get the data
47 device.write("OUTPDATA?")
48 data=device.read(15*numPoints*2);
49
50 #Break the data into lists
51 dataList = re.findall(r'[-+.E0-9]+',data)
52
53 # Print data
54 j=0;
55 for i in range(len(freqList)):
56 print freqList[i], dataList[j], dataList[j+1]
57 j=j+2;
58
59 else:
60 # It is spectrum analyzer mode
61
62 #Check if it is the dual channel mode or not
63 device.write('DUAC?')
64 numOfChan = int(device.read()) +1
65
66 #Get the data
67 dataList=[]
68 for i in range(1,numOfChan+1):
69 device.write("OUTPDATA?")
70 data=device.read(15*numPoints)
71 #Break into elements
72 data=re.findall(r'[-+.E0-9]+',data)
73 #Append to dataList
74 dataList.append(data)
75
76 # Print data
77 for i in range(len(freqList)):
78 print freqList[i],
79 for j in range(0, numOfChan):
80 print dataList[j][i],
81
82 print
83
84
85
86 #Resume the measurement
87 device.write("CONT")
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.
