specana.py

来自「对Spectrum Analyzer进行编辑」· Python 代码 · 共 63 行

PY
63
字号
# specAna.py
#   Defines the SpecAna class
#
# Paul Lettieri
# Started March 2007
#
# $Id: specAna.py,v 1.1 2007/03/09 02:34:48 lettieri Exp $


try:
    import visa
except:
    print   '''WARNING: Could not import visa; either its not installed,
                or this computer does not have a GPIB card;  either way,
            '''


class SpecAna:
    '''Spectrum Analyzer Class

        Finds the first Rohde&Schwarz device on your GPIB,
        and assumes it to be a spectrum analyzer, which then
        may be programmed through various accessors.

        NOTE: Should be expanded to allow for other brands,
        and or other Rohde&Schwarz type devices
    '''
    def __init__(self):
        self.sa = []
        try:
            instr = visa.get_instruments_list()
            for i in instr:
                if i[:4]=='GPIB':
                    self.sa = visa.instrument(i)
                    if self.sa.ask("*IDN?")[:13] == 'Rohde&Schwarz':
                        break
                    self.sa.close()
            print "Found %s at %s" % (self.sa.ask("*IDN?"),i)
        except:
            print "WARNING: Could not locate a R&S spectrum analyzer"

    def close(self):
        if self.sa:
            self.sa.close()

    def setFreq(self,freq):
        if self.sa:
            self.sa.write("FREQ:CENT %f Hz" % freq)

    def setSpan(self,freq):
        if self.sa:
            self.sa.write("FREQ:SPAN %f Hz" % freq)

    def setAvg(self):
        if self.sa:
            self.sa.write("DISP:TRAC:MODE AVER")

    def getSweepTime(self):
        if self.sa:
            return self.sa.ask("SWE:TIME?")
        else:
            return 0

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?