view agilent_r5071.py @ 81:1947d10f9395

- Search for signal frequency iteratively to improve accuracy. - Use narrower bandwidths (via FFT filter) for close in measurements. - Work around bug in firmware when using FFT filter. - Actually _raise_ the exception when the signal power is too low.
author Daniel O'Connor <doconnor@gsoft.com.au>
date Fri, 27 Sep 2024 16:56:44 +0930
parents 6bd941d96c03
children
line wrap: on
line source

# Docs are at http://ena.tm.agilent.com/e5071c/manuals/webhelp/eng/

import numpy
import scpi
import pylab

fname = 'data'

# Connect
inst = scpi.instURL('vxi://203.31.81.47')

# Read ID
inst.write('*IDN?')
inst.read()
# 'Agilent Technologies,E5071C,MY46109815,A.09.54\n'

# Set to 8 byte floats
inst.write(":FORM:DATA REAL")

# Set to little endian
inst.write(':FORM:BORD SWAP')

# Grab frequency data
inst.write(":SENS1:FREQ:DATA?")
freqs = scpi.bindecode(inst.read(), dtype = numpy.float64)

# Grab trace data
inst.write(":CALC1:TRACE1:DATA:FDATA?")
dat = scpi.bindecode(inst.read(), dtype = numpy.float64)

# We only want the real part (no imag for this measurement)
dat = dat[::2]

# Plot
pylab.plot(freqs, dat)
pylab.show()

# Save for later
numpy.savez('data.npz', freqs, dat)

# Load..
f = numpy.load(fname + '.npz')
freqs = f['arr_0']
dat = f['arr_1']

f = file(fname + '.csv', 'wb')
f.write("Frequencies\n")
numpy.savetxt(f, [freqs], delimiter = ',')
f.write("Gain\n")
numpy.savetxt(f, [dat], delimiter = ',')
del f