## sweepfrequency.py [-f filename] [-i ip_address] [-a startFreq] [-z endFreq] [-s stepFreq] [-m numAvg] # ## This script sweeps the frequency of a Marconi local oscillator, within the range ## delimited by startFreq and endFreq, with a step set by stepFreq. An arbitary ## signal is monitored on a HP8590 spectrum analyzer and the scripts records the ## amplitude of the spectrum at the frequency injected by the Marconi at the moment. ## The GPIB address of the Marconi is assumed to be 17, that of the HP Spectrum Analyzer to be 18 ## Alberto Stochino, October 2008 import re import sys import math from optparse import OptionParser from socket import * import HP8590PRC #Parse options parser = OptionParser() parser.add_option("-f", "--file", dest="filename", help="Output file name without an extension", default="data") parser.add_option("-i", "--ip", dest="ipAddress", default="gpib01", help="IP address/Host name") parser.add_option("-a", "--af", dest="startFreq", default=1e6, help="start frequency scan") parser.add_option("-z", "--zf", dest="endFreq", default=1e6, help="end frequency scan") parser.add_option("-s", "--sf", dest="stepFreq", default=1e6, help="frequency scanning step") parser.add_option("-m", "--avg", dest="numAvg", default=1, help="number of averaged points per step") (options, args) = parser.parse_args() # Open socket print('Connecting to '+str(options.ipAddress)) netAddr=(options.ipAddress, 1234) netSock = socket(AF_INET, SOCK_STREAM) netSock.connect(netAddr) # open files dataFileName=options.filename+'.dat' dataFile = open(dataFileName,'w') print('Data will be written into '+dataFileName) #Call suitable functions for getting data HP8590PRC.getdata(netSock, options.startFreq, options.endFreq, options.stepFreq, options.numAvg, dataFile) dataFile.close() netSock.close()