1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
| # Main function
def main():
# Get the Command Line parameters in first
argv = sys.argv
# Debug Args for testing various modes (overrides command line inputs)
# Uncomment to use
#argv = ["",""]
#argv = ["-i","192.168.1.2", "-n","100","-b","ASCII","-f","iqdata.txt"]
#argv = ["-i","192.168.1.2", "-n","1000000","-b","BIN","-f","iqdata.iqw","-a","1MHz"]
#argv = ["-i","192.168.1.2", "-n","1000","-b","BIN","-f","iqdata.iqw","-a","1MHz"]
# Check some arguments have been entered
if len(argv) > 1 :
if argv[1] == "-h":
print "Program Usage:\n"
#80 charachter line
#-------------------------------------------------------------------------------
print "This program captures IQ Data as IQ Pairs from R&S Spectrum Analysers"
print "The data can then be easily manipulated and changed to a Waveform file"
print "to run on an R&S signal generator by using Arb Toolbox (1GP62)\n"
print "Command Examples:"
print "fsxiqcapture.exe -h => Gives these instructions"
print "fsxiqcapture.exe param1 param2 ...\n"
print "-i IP address e.g. -i 192.168.1.2"
print "-f Output File e.g. -f iqcapture.txt, default = iqcapture.txt"
print "-b Read Type e.g. -b BIN or -b ASCII, default = ASCII"
print "-r Resolution BW e.g. -r 10MHz, default = 10MHz"
print "-t Trigger setting e.g. -t IMM or -t EXT, default = IMM"
print "-a Sample Rate e.g. -a 10MHz, default = 10MHz"
print "-n No. Captured IQ Sample Pairs e.g. -n 2048, default = 2048"
print "-d Analyser Display On or Off e.g. -d ON or -d OFF, default = ON"
else:
# Process input args
count = 0
ipaddress = ""
outfile = ""
readtype = ""
rbw = ""
samprate = ""
trigger = ""
nosamples = ""
dispupdate = ""
vdebug = ""
while count < len(argv):
x = argv[count]
if x == "-i":
ipaddress = argv[count+1]
elif x == "-f":
outfile = argv[count+1]
elif x == "-b":
readtype = argv[count+1].upper()
elif x == "-r":
rbw = argv[count+1]
elif x == "-t":
trigger = argv[count+1].upper()
elif x == "-a":
samprate = argv[count+1]
elif x == "-n":
nosamples = argv[count+1]
elif x == "-d":
dispupdate = argv[count+1].upper()
count += 1
if ipaddress == "": ipaddress = "192.168.1.2"
if readtype == "": readtype = "ASCII"
if outfile == "": outfile = "iqcapture.txt"
if rbw == "": rbw = "10MHz"
if samprate == "": samprate = "10MHz"
if trigger == "": trigger = "IMM"
if nosamples == "": nosamples = "2048"
if dispupdate == "": dispupdate = "ON"
# Create an instance of the class and connect to the instruments
fsx = scpicontrol.scpicontrol(timeout)
fsx.connect(ipaddress,int(port))
if fsx.connected == True:
res = fsx.ask(debug,"*IDN?")
if res != False:
print "Instrument Connected: " + res
print "RBW is: " + rbw
print "Trigger setting is: " + trigger
print "Sample Rate is: " + samprate
print "No. Samples requested: " + format(int(nosamples),",d")
print "Analyser Display is: " + dispupdate
# Update the screen
fsx.write(debug,"SYST:DISP:UPD " + dispupdate)
# Continous sweep off so we can do synchronous reads
fsx.write(debug,"INIT:CONT OFF")
# Turn IQ capture ON
fsx.write(debug,"TRAC:IQ:STAT ON")
# Set RBW, Sample Rate, Trigger, tigger slope, pre-trig samples, no.samples
fsx.write(debug,"TRAC:IQ:SET NORM,"+rbw+","+samprate+","+trigger+",POS,0,"+nosamples)
# Get the IQ data
# Create new IQReader Object
iqr = iqreader.iqreader(fsx.handle)
if readtype == "BIN":
fsx.write(debug,"FORM REAL,32")
fsx.write(debug,"TRACe:IQ:DATA:FORMat IQPair")
fsx.write(debug,"TRAC:IQ:DATA?")
iqr.biniqread(nosamples,outfile) # Read as binary
elif readtype == "ASCII":
fsx.write(debug,"FORM ASCii")
fsx.write(debug,"TRACe:IQ:DATA:FORMat IQPair")
fsx.write(debug,"TRAC:IQ:DATA?")
iqr.asciiiqread(outfile) # Read as ASCII
print "IQ saved to: " + outfile
# Disconnect and close the socket
if fsx.connected == True: fsx.disconnect()
else:
print "No Arguments Passed"
# Boilerplate syntax, call the main function
# Seems to significantly speed up script execution
if __name__ == "__main__":
# Save the start time
startTime = datetime.now()
main()
# Print script runtime
print "Script Run Time: " + str(datetime.now()-startTime) |