# This function provides the measuremeent of the peak amplitude on the spectrum analyzer # HP8590 analyzer while sweeping the excitation frequency on the function generator. # # Alberto Stochino 2008 import re import sys import math from optparse import OptionParser from socket import * import time def getdata(netSock, startFreq, endFreq, stepFreq, numAvg, dataFile): # Initializations of all the device netSock.send("++eos 3\n") time.sleep(0.2) netSock.send("++clr\n") time.sleep(0.2) netSock.send("++auto 0\n") time.sleep(0.2) netSock.send("++ifc\n") time.sleep(0.2) netSock.send("++read_tmo_ms 4000\n") netSock.send("++auto 0\n") time.sleep(0.2) netSock.send("++addr 17\n") time.sleep(0.2) netSock.send("RFLV:VALUE 0DBM;ON;\n") time.sleep(0.2) netSock.send("++addr 18\n") netSock.send("++mode 1") netSock.send("++auto 1\n") time.sleep(0.2) netSock.send("ip\n") time.sleep(1) netSock.send("cf "+str(startFreq)+"HZ\n;sp 50khz\n;ts\n") netSock.send("++addr 17\n") netSock.send("++auto 0\n") tmpData = 0 m = int(numAvg) StepSign = 1 if int(startFreq) > int(endFreq): StepSign = -1 for freq in range(int(startFreq), int(endFreq)+StepSign*int(stepFreq), StepSign*int(stepFreq)): netSock.send("cfrq:value "+str(freq)+"HZ\n") # change the frequency of the Marconi #print('ciao') time.sleep(0.3) # data decimation if if abs(freq-int(startFreq))%(10*int(stepFreq)) == 0.0: netSock.send("++addr 18\n") time.sleep(0.2) # settle down time netSock.send("cf "+str(freq)+"HZ;ts\n") # place the marker at the frequency of the Marconi tmpData = 0.0; tmp =0.0 time.sleep(0.2) # settle down time # Averaging cycle for i in range(0,m): netSock.send("mkpk;mka?\n") netSock.send("++read eoi\n") tmp = netSock.recv(1024) tmp = re.findall(r'^[^\r]*', tmp, re.M) tmp = str(tmp[0]) tmpData = tmpData + float(tmp) if m > 1: time.sleep(0.33) tmpData = tmpData / m netSock.send("++addr 17\n") # File writing dataFile.write(str(freq)+'\t'+str(tmpData)+'\n')