Initial commit
This commit is contained in:
commit
9599810278
|
@ -0,0 +1,2 @@
|
|||
.virtenv
|
||||
__pycache__
|
|
@ -0,0 +1,47 @@
|
|||
#!/bin/env python3
|
||||
|
||||
import usbtmc
|
||||
|
||||
READ_CHUNK_SIZE = 256
|
||||
|
||||
class SSA3023(object):
|
||||
def __init__(self):
|
||||
self.instr = usbtmc.Instrument(0xf4ec, 0x1300)
|
||||
#TODO: Check if ID number matches
|
||||
#id_str = self.instr.ask("*IDN?")
|
||||
|
||||
self.instr.write(":FORMat:TRACe:DATA ASCii")
|
||||
|
||||
def get_start_freq(self):
|
||||
return float(self.instr.ask(":SENSe:FREQuency:STARt?"))
|
||||
|
||||
def get_stop_freq(self):
|
||||
return float(self.instr.ask(":SENSe:FREQuency:STOP?"))
|
||||
|
||||
def get_ref_level(self):
|
||||
return float(self.instr.ask(":DISPlay:WINDow:TRACe:Y:SCALe:RLEVel?"))
|
||||
|
||||
def get_norm_ref_level(self):
|
||||
return float(self.instr.ask(":DISPlay:WINDow:TRACe:Y:NRLevel?"))
|
||||
|
||||
def is_displayed_trace(self, num):
|
||||
if num < 1 or num > 4:
|
||||
raise ValueError("%d is not a valid trace %d", num)
|
||||
res = self.instr.ask(":TRACe%d:MODE?" % num)
|
||||
|
||||
return res != "BLANk"
|
||||
|
||||
def get_trace(self, num):
|
||||
if num < 1 or num > 4:
|
||||
raise ValueError("%d is not a valid trace %d", num)
|
||||
|
||||
self.instr.write(":TRACe:DATA? %d" % num)
|
||||
data = b''
|
||||
while not data.endswith(b'\n'):
|
||||
chunk = self.instr.read_raw(num=READ_CHUNK_SIZE)
|
||||
data = data + chunk
|
||||
|
||||
data = data.decode("utf-8").split(',')[:-1]
|
||||
data = map(lambda x: float(x), data)
|
||||
|
||||
return list(data)
|
|
@ -0,0 +1,47 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import usbtmc
|
||||
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib.ticker import EngFormatter
|
||||
|
||||
from ssa3032tmc import SSA3023
|
||||
|
||||
def main():
|
||||
|
||||
ssa = SSA3023()
|
||||
|
||||
start_freq = ssa.get_start_freq()
|
||||
stop_freq = ssa.get_stop_freq()
|
||||
norm_level = ssa.get_norm_ref_level()
|
||||
|
||||
fig = plt.figure()
|
||||
ax = fig.add_subplot(111)
|
||||
formatterHz = EngFormatter(unit='Hz')
|
||||
ax.xaxis.set_major_formatter(formatterHz)
|
||||
|
||||
ax.set_xlim(start_freq, stop_freq)
|
||||
ax.grid()
|
||||
|
||||
min_level = norm_level
|
||||
|
||||
for i in [1,2,3,4]:
|
||||
if ssa.is_displayed_trace(i):
|
||||
samples = np.array(ssa.get_trace(i))
|
||||
min_level = min(np.min(samples), min_level)
|
||||
freqs = np.linspace(start_freq, stop_freq, len(samples))
|
||||
ax.plot(freqs, samples, label="Trace %d" % i)
|
||||
|
||||
ax.set_ylim(min_level - 10, norm_level)
|
||||
ax.legend()
|
||||
plt.show()
|
||||
|
||||
|
||||
|
||||
|
||||
plt.show()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,47 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import usbtmc
|
||||
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib.ticker import EngFormatter
|
||||
|
||||
from ssa3032tmc import SSA3023
|
||||
|
||||
def main():
|
||||
|
||||
ssa = SSA3023()
|
||||
|
||||
fig = plt.figure()
|
||||
ax = fig.add_subplot(111)
|
||||
|
||||
|
||||
while True:
|
||||
ax.clear()
|
||||
start_freq = ssa.get_start_freq()
|
||||
stop_freq = ssa.get_stop_freq()
|
||||
norm_level = ssa.get_norm_ref_level()
|
||||
|
||||
formatterHz = EngFormatter(unit='Hz')
|
||||
ax.xaxis.set_major_formatter(formatterHz)
|
||||
|
||||
ax.set_xlim(start_freq, stop_freq)
|
||||
ax.grid()
|
||||
|
||||
min_level = norm_level
|
||||
|
||||
for i in [1,2,3,4]:
|
||||
if ssa.is_displayed_trace(i):
|
||||
samples = np.array(ssa.get_trace(i))
|
||||
min_level = min(np.min(samples), min_level)
|
||||
freqs = np.linspace(start_freq, stop_freq, len(samples))
|
||||
ax.plot(freqs, samples, label="Trace %d" % i)
|
||||
|
||||
ax.set_ylim(min_level - 10, norm_level)
|
||||
ax.legend()
|
||||
|
||||
plt.pause(0.250)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in New Issue