示例#1
0
def plot_main():
    try:
        fpga = casperfpga.katcp_fpga.KatcpFpga(roach_ppc_ip, timeout=20.)
    except RuntimeError:
        fpga = None
    # Roach interface
    ri = roachInterface(sys.argv[1], fpga, gc, regs)
    while 1:
        plot_opt(ri)
    return
示例#2
0
def plot_main():
    try:
        fpga = casperfpga.katcp_fpga.KatcpFpga(roach_ppc_ip, timeout = 3.)
    except (RuntimeError, AttributeError):
        fpga = None
    # Roach interface
    ri = roachInterface(fpga, gc, regs, None)
    while 1:
        plot_opt(ri)
    return
示例#3
0
def systemInit():
    fpga = getFPGA()
    if not fpga:
        print "\nROACH link is down"
        return
    # Valon object
    #valon = getValon()
    valon = None
    # Roach PPC object
    fpga = getFPGA()
    # Roach interface
    ri = roachInterface(fpga, gc, regs, valon)
    if (ri.uploadfpg() < 0):
        print "\nFirmware upload failed"
    time.sleep(0.3)
    # UDP socket
    s = socket(AF_PACKET, SOCK_RAW, htons(3))
    # UDP object
    udp = roachDownlink(ri, fpga, gc, regs, s, ri.accum_freq)
    try:

        # Windfreak calibration
        #cal = rfcalibration.CalibrationRF(synthID, attenID)
        #cal.setSynthToDefault(clkFreq, clkPow, LOFreq, LOPow)
        #cal.calibrateADC(fpga, target_rms_mv, attOut, attIn) # ADC level calibration

        #initValon(valon)
        print "Valon initiliazed"
    except OSError:
        print '\033[93mValon Synthesizer could not be initialized: Check comm port and power supply\033[93m'
        return
    except IndexError:
        print '\033[93mValon Synthesizer could not be initialized: Check comm port and power supply\033[93m'
        return
    fpga.write_int(regs[np.where(regs == 'accum_len_reg')[0][0]][1],
                   ri.accum_len - 1)
    time.sleep(0.1)
    fpga.write_int(regs[np.where(regs == 'dds_shift_reg')[0][0]][1],
                   int(gc[np.where(gc == 'dds_shift')[0][0]][1]))
    time.sleep(0.1)
    #ri.lpf(ri.boxcar)
    if (ri.qdrCal() < 0):
        print '\033[93mQDR calibration failed... Check FPGA clock source\033[93m'
        return
    else:
        fpga.write_int(regs[np.where(regs == 'write_qdr_status_reg')[0][0]][1],
                       1)
    time.sleep(0.1)
    try:
        udp.configDownlink()
        print "UDP Downlink configured!"
    except AttributeError:
        print "UDP Downlink could not be configured. Check ROACH connection."
        return
    return
示例#4
0
def plot_main():
    try:
        fpga = casperfpga.CasperFpga(
            gc[np.where(gc == 'roach_ppc_ip')[0][0]][1], timeout=3.)
    except RuntimeError:
        fpga = None
    # Roach interface
    ri = roachInterface(fpga, gc, regs, None)
    while 1:
        plot_opt(ri)
    return
示例#5
0
def vnaSweepConsole():
    """Does a wideband sweep of the RF band, saves data in vna_savepath
       as .npy files"""
    # UDP socket
    s = socket(AF_PACKET, SOCK_RAW, htons(3))
    # Valon object
    #valon = getValon()
    valon = None
    # Roach PPC object
    fpga = getFPGA()
    # Roach interface
    ri = roachInterface(fpga, gc, regs, valon)
    # UDP object
    udp = roachDownlink(ri, fpga, gc, regs, s, ri.accum_freq)
    udp.configSocket()
    Navg = np.int(gc[np.where(gc == 'Navg')[0][0]][1])
    if not os.path.exists(vna_savepath):
        os.makedirs(vna_savepath)
    sweep_dir = vna_savepath + '/' + \
       str(int(time.time())) + '-' + time.strftime('%b-%d-%Y-%H-%M-%S') + '.dir'
    os.mkdir(sweep_dir)
    np.save("./last_vna_dir.npy", sweep_dir)
    print sweep_dir
    #valon.set_frequency(LO, center_freq/1.0e6)
    span = ri.pos_delta
    print "Sweep Span =", 2 * np.round(ri.pos_delta, 2), "Hz"
    start = center_freq * 1.0e6 - (span)
    stop = center_freq * 1.0e6 + (span)
    sweep_freqs = np.arange(start, stop, lo_step)
    sweep_freqs = np.round(sweep_freqs / lo_step) * lo_step
    if not np.size(ri.freq_comb):
        ri.makeFreqComb()
    np.save(sweep_dir + '/bb_freqs.npy', ri.freq_comb)
    np.save(sweep_dir + '/sweep_freqs.npy', sweep_freqs)
    Nchan = len(ri.freq_comb)
    if not Nchan:
        Nchan = fpga.read_int(
            regs[np.where(regs == 'read_comb_len_reg')[0][0]][1])
    idx = 0
    while (idx < len(sweep_freqs)):
        print 'LO freq =', sweep_freqs[idx] / 1.0e6
        #valon.set_frequency(LO, sweep_freqs[idx]/1.0e6)
        time.sleep(0.2)
        #time.sleep(0.1)
        if (udp.saveSweepData(Navg, sweep_dir, sweep_freqs[idx], Nchan) < 0):
            continue
        else:
            idx += 1
        #time.sleep(0.1)
    #valon.set_frequency(LO, center_freq) # LO
    return
示例#6
0
def calibrateADC(target_rms_mv, outAtten, inAtten):
    """Automatically set RUDAT attenuation values to achieve desired ADC rms level
       inputs:
           float target_rms_mv: The target ADC rms voltage level, in mV,
                                for either I or Q channel
           float outAtten: Starting output attenuation, dB
           float inAtten: Starting input attenuation, dB"""
    #setAtten(outAtten, inAtten)
    fpga = getFPGA()
    valon = None
    ri = roachInterface(fpga, gc, regs, valon)
    print "Start atten:", outAtten, inAtten
    rmsI, rmsQ, __, __ = ri.rmsVoltageADC()
    avg_rms_0 = (rmsI + rmsQ) / 2.
    print "Target RMS:", target_rms_mv, "mV"
    print "Current RMS:", avg_rms_0, "mV"
    if avg_rms_0 < target_rms_mv:
        avg_rms = avg_rms_0
        while avg_rms < target_rms_mv:
            time.sleep(0.1)
            if inAtten > 1:
                inAtten -= 1
            else:
                outAtten -= 1
            if (inAtten == 1) and (outAtten == 1):
                break
            #setAtten(outAtten, inAtten)
            rmsI, rmsQ, __, __ = ri.rmsVoltageADC()
            avg_rms = (rmsI + rmsQ) / 2.
            outA, inA = 0, 0  #readAtten()
            print outA, inA
    if avg_rms_0 > target_rms_mv:
        avg_rms = avg_rms_0
        while avg_rms > target_rms_mv:
            time.sleep(0.1)
            if outAtten < 30:
                outAtten += 1
            else:
                inAtten += 1
            if (inAtten > 30) and (outAtten > 30):
                break
            #setAtten(outAtten, inAtten)
            rmsI, rmsQ, __, __ = ri.rmsVoltageADC()
            avg_rms = (rmsI + rmsQ) / 2.
            outA, inA = 0, 0  #readAtten()
            print outA, inA
    new_out, new_in = 0, 0  #readAtten()
    print
    print "Final atten:", new_out, new_in
    print "Current RMS:", avg_rms, "mV"
    return
示例#7
0
 def testConn(self, fpga):
     """Tests the link to Roach2 PPC, using return from getFPGA()
         inputs:
             casperfpga object fpga: The fpga object
         outputs: the fpga object"""
     if not fpga:
         try:
             fpga = casperfpga.CasperFpga(self.roach_ip, timeout=3.)
             # Roach interface
             self.ri = roachInterface(self.fpga, self.gc, self.regs, None)
         except RuntimeError:
             logging.warning(
                 "No connection to ROACH. If booting, wait 30 seconds and retry. Otherwise, check gc config."
             )
     return fpga
示例#8
0
def writeVnaComb(cw=False):
    # Roach PPC object
    fpga = getFPGA()
    if not fpga:
        print "\nROACH link is down"
        return
    # Roach interface
    ri = roachInterface(fpga, gc, regs, None)
    try:
        if cw:
            ri.freq_comb = test_freq
        else:
            ri.makeFreqComb()
        if (len(ri.freq_comb) > 400):
            fpga.write_int(regs[np.where(regs == 'fft_shift_reg')[0][0]][1],
                           2**5 - 1)
            time.sleep(0.1)
        else:
            fpga.write_int(regs[np.where(regs == 'fft_shift_reg')[0][0]][1],
                           2**9 - 1)
            time.sleep(0.1)
        ri.upconvert = np.sort(
            ((ri.freq_comb + (center_freq) * 1.0e6)) / 1.0e6)
        print "RF tones =", ri.upconvert
        ri.writeQDR(ri.freq_comb, transfunc=False)
        np.save("last_freq_comb.npy", ri.freq_comb)
        if not (fpga.read_int(
                regs[np.where(regs == 'dds_shift_reg')[0][0]][1])):
            if regs[np.where(regs == 'DDC_mixerout_bram_reg')[0]
                    [0]][1] in fpga.listdev():
                shift = ri.return_shift(0)
                if (shift < 0):
                    print "\nError finding dds shift: Try writing full frequency comb (N = 1000), or single test frequency. Then try again"
                    return
                else:
                    fpga.write_int(
                        regs[np.where(regs == 'dds_shift_reg')[0][0]][1],
                        shift)
                    print "Wrote DDS shift (" + str(shift) + ")"
            else:
                fpga.write_int(
                    regs[np.where(regs == 'dds_shift_reg')[0][0]][1],
                    ri.dds_shift)
    except KeyboardInterrupt:
        return
    return
示例#9
0
def main():
    pi = None
    s = None
    try:
        fpga = casperfpga.katcp_fpga.KatcpFpga(roach_ppc_ip, timeout = 3.)
    except (RuntimeError, AttributeError):
        fpga = None
    
    # UDP socket
    s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(3))

    # Roach interface
    ri = roachInterface(fpga, gc, regs, None)

    # GbE interface
    udp = roachDownlink(ri, fpga, gc, regs, network, s, ri.accum_freq)
    udp.configSocket()
    
    #os.system('clear')
    while 1:
        try:
            upload_status = 0
            name = ''
            build_time = ''
            if fpga:
	        if fpga.is_running():
                    firmware_info = fpga.get_config_file_info()
                    name = firmware_info['name']
                    build_time = firmware_info['build_time']
                    upload_status = 1
	    time.sleep(0.1)
            pi = piSocket(FC2)
            upload_status = main_opt(fpga, ri, udp, pi, upload_status, name, build_time)
	    if pi:
	        pi.shutdown(1)
	        pi.close()
        except KeyboardInterrupt:
	    if pi:
	        pi.shutdown(1)
	        pi.close()
	    break
    return
示例#10
0
def main():
    """Main function, try to initialize the system the first time, then open the menu"""

    s = None
    try:
        fpga = casperfpga.CasperFpga(roach_ip, timeout = 120.)
        print "\nConnected to: " + roach_ip
    except RuntimeError:
        fpga = None
        print "\nRoach link is down"

    # UDP socket
    s = socket(AF_PACKET, SOCK_RAW, htons(3))

    # Roach interface
    ri = roachInterface(fpga, gc, regs, None)

    # Windfreak synthesizer
    synthRF = synthclass.Synthesizer(synthID)

    # GbE interface
    udp = roachDownlink(ri, fpga, gc, regs, s, ri.accum_freq)
    udp.configSocket()

    os.system('clear')

    valon = None

    while 1:
        try:
            upload_status = 0
            if fpga:
                if fpga.is_running():
                    upload_status = 1
            time.sleep(0.1)
            #fpga = None
            #ri = None
            #udp = None
            upload_status = main_opt(fpga, ri, udp, valon, upload_status)
        except TypeError:
            pass
    return
示例#11
0
def main():
    pi = None
    s = None
    try:
        fpga = casperfpga.katcp_fpga.KatcpFpga(roach_ppc_ip, timeout=20.)
    except (RuntimeError, AttributeError):
        fpga = None

    # UDP socket
    s = socket(AF_PACKET, SOCK_RAW, htons(3))

    # Roach interface
    ri = roachInterface(sys.argv[1], fpga, gc, regs)

    # GbE interface
    udp = roachDownlink(ri, fpga, gc, regs, s, ri.accum_freq)
    udp.configSocket()

    #os.system('clear')
    while 1:
        upload_status = 0
        name = ''
        build_time = ''
        if fpga and fpga.is_running():
            upload_status = 1
        if not pi:
            try:
                print "Opening pi socket"
                pi = piSocket(FC1)
            except (TypeError, KeyboardInterrupt):
                #if pi:
                #pi.shutdown(1)
                #pi.close()
                pass
                #break
        try:
            upload_status = main_opt(fpga, ri, udp, pi, upload_status, name,
                                     build_time)
        except KeyboardInterrupt:
            break
    return
示例#12
0
def main():
    s = None
    try:
        fpga = casperfpga.CasperFpga(
            gc[np.where(gc == 'roach_ppc_ip')[0][0]][1], timeout=120.)
    except RuntimeError:
        fpga = None
    # UDP socket
    s = socket(AF_PACKET, SOCK_RAW, htons(3))

    # Valon synthesizer instance
    try:
        #valon = valon_synth9.Synthesizer(gc[np.where(gc == 'valon_comm_port')[0][0]][1])
        valon = None
        print "$NO VALON$"
    except OSError:
        "Valon could not be initialized. Check comm port and power supply."

    # Roach interface
    ri = roachInterface(fpga, gc, regs, valon)

    # GbE interface
    udp = roachDownlink(ri, fpga, gc, regs, s, ri.accum_freq)
    udp.configSocket()
    os.system('clear')
    while 1:
        try:
            upload_status = 0
            if fpga:
                if fpga.is_running():
                    #firmware_info = fpga.get_config_file_info()
                    upload_status = 1
            time.sleep(0.1)
            upload_status = main_opt(fpga, ri, udp, valon, upload_status)
        except TypeError:
            pass
    return
示例#13
0
    def __init__(self):
        QtGui.QMainWindow.__init__(self)

        # Load of main window GUI
        # The GUI was developed in QT Designer
        self.ui = uic.loadUi("src/gui/main.ui")

        # Full Screen
        self.ui.showMaximized()
        screen = QtGui.QDesktopWidget().screenGeometry()

        # Screen dimensions
        self.size_x = screen.width()
        self.size_y = screen.height()

        self.ui.setWindowFlags(self.ui.windowFlags()
                               | QtCore.Qt.CustomizeWindowHint)
        self.ui.setWindowFlags(self.ui.windowFlags()
                               & ~QtCore.Qt.WindowMaximizeButtonHint)

        self.ui.ctrlFrame.resize(280, self.size_y - 120)
        self.ui.tabPlots.resize(self.size_x - 600, self.size_y - 150)

        self.ui.plotFrame.resize(self.size_x - 620, self.size_y - 210)
        self.ui.plotFrame.setLayout(self.ui.MainPlot)

        self.ui.plotFrame_2.resize(self.size_x - 620, self.size_y - 210)
        self.ui.plotFrame_2.setLayout(self.ui.MainPlot_2)

        self.ui.Terminal.move(self.size_x - 290, self.size_y / 2 - 100)
        self.ui.Terminal.resize(self.size_x - 1085, self.size_y / 2 - 30)
        self.ui.Terminal.setLayout(self.ui.TermVBox)

        self.ui.loggsFrame.move(self.size_x - 290, 10)
        self.ui.loggsFrame.resize(self.size_x - 1085, self.size_y / 2 - 120)
        self.ui.loggsFrame.setLayout(self.ui.loggsText)

        # Logging
        logTextBox = QTextEditLogger(self)
        # You can format what is printed to text box
        logTextBox.setFormatter(
            logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
        logging.getLogger().addHandler(logTextBox)
        # You can control the logging level
        logging.getLogger().setLevel(logging.INFO)
        self.ui.loggsText.addWidget(logTextBox.widget)

        # Initial settings
        # Loading General Configuration file

        # Load general settings
        self.gc = {}
        with open("./config/general_config") as f:
            for line in f:
                if line[0] != "#" and line[0] != "\n":
                    (key, val) = line.split()
                    self.gc[key] = val

        logging.info('Loading configuration parameters ...')

        # Load list of firmware registers (note: must manually update for different versions)
        self.regs = {}
        with open("./config/firmware_registers") as f:
            for line in f:
                if line[0] != "#" and line[0] != "\n":
                    (key, val) = line.split()
                    self.regs[key] = val

        logging.info('Loading firmware registers ...')

        # Paths of firmware and directories to save data
        self.firmware = self.gc['FIRMWARE_FILE']
        self.ui.firmEdit.setText(self.firmware)

        self.vna_savepath = self.gc['VNA_SAVEPATH']
        self.targ_savepath = self.gc['TARG_SAVEPATH']
        self.dirfile_savepath = self.gc['DIRFILE_SAVEPATH']
        self.ui.vnaEdit.setText(self.vna_savepath)
        self.ui.tarEdit.setText(self.targ_savepath)
        self.ui.streamEdit.setText(self.dirfile_savepath)

        # UDP packet
        self.buf_size = int(self.gc['buf_size'])
        self.header_len = int(self.gc['header_len'])

        # Ethernet port
        self.eth_port = self.gc['udp_dest_device']
        self.ui.ethEdit.setText(self.eth_port)
        os.system("sudo ip link set " + self.eth_port + " mtu 9000")

        # Source (V6) Data for V6
        self.udp_src_ip = self.gc['udp_src_ip']
        self.udp_src_mac = self.gc['udp_src_mac']
        self.udp_src_port = self.gc['udp_src_port']

        self.ui.ipSrcEdit.setText(self.udp_src_ip)
        self.ui.macSrcEdit.setText(self.udp_src_mac)
        self.ui.portSrcEdit.setText(self.udp_src_port)

        self.dds_shift = self.gc['dds_shift']

        self.udp_dst_ip = self.gc['udp_dest_ip']
        self.udp_dst_mac = self.gc['udp_dest_mac']
        self.udp_dst_port = self.gc['udp_dst_port']
        self.ui.ipDstEdit.setText(self.udp_dst_ip)
        self.ui.macDstEdit.setText(self.udp_dst_mac)
        self.ui.portDstEdit.setText(self.udp_dst_port)

        # About the ROACH
        self.roach_ip = self.gc['roach_ppc_ip']
        self.ui.roachIPEdit.setText(self.roach_ip)

        # Windfreak Synthesizer params
        self.synthID = self.gc['synthID']
        self.clkFreq = np.float(self.gc['clkFreq'])
        self.clkPow = np.float(self.gc['clkPow'])
        self.LOFreq = np.float(self.gc['LOFreq'])
        self.LOPow = np.float(self.gc['LOPow'])
        self.center_freq = np.float(self.gc['center_freq'])

        self.lo_step = np.float(self.gc['lo_step'])

        self.ui.freqClk.setText(str(self.clkFreq))
        self.ui.powClk.setText(str(self.clkPow))
        self.ui.loFreq.setText(str(self.LOFreq))
        self.ui.loPow.setText(str(self.LOPow))

        # Limits of test comb
        self.min_pos_freq = np.float(self.gc['min_pos_freq'])
        self.max_pos_freq = np.float(self.gc['max_pos_freq'])
        self.min_neg_freq = np.float(self.gc['min_neg_freq'])
        self.max_neg_freq = np.float(self.gc['max_neg_freq'])
        self.symm_offset = np.float(self.gc['symm_offset'])
        self.Nfreq = int(self.gc['Nfreq'])

        self.ui.minPosEdit.setText(str(self.min_pos_freq / 1.0e6))
        self.ui.maxPosEdit.setText(str(self.max_pos_freq / 1.0e6))
        self.ui.minNegEdit.setText(str(self.min_neg_freq / 1.0e6))
        self.ui.maxNegEdit.setText(str(self.max_neg_freq / 1.0e6))
        self.ui.offsetEdit.setText(str(self.symm_offset / 1.0e6))
        self.ui.nFreqsEdit.setText(str(self.Nfreq))

        # Attenuation
        att_ID_1 = int(self.gc['att_ID_1'])
        att_ID_2 = int(self.gc['att_ID_2'])

        self.attenID = [att_ID_1, att_ID_2]

        self.ui.attInIDEdit.setText(str(att_ID_1))
        self.ui.attOutIDEdit.setText(str(att_ID_2))

        self.att_In = int(self.gc['attIn'])
        self.att_Out = int(self.gc['attOut'])
        self.target_rms = np.float(self.gc['target_rms_mv'])

        self.ui.attInEdit.setText(str(self.att_In))
        self.ui.attOutEdit.setText(str(self.att_Out))
        self.ui.tarLevelEdit.setText(str(self.target_rms))

        # Optional test frequencies
        self.test_freq = np.float(self.gc['test_freq'])
        self.test_freq = np.array([self.test_freq])
        self.freq_list = self.gc['freq_list']

        # Parameters for resonator search
        self.smoothing_scale = np.float(self.gc['smoothing_scale'])
        self.peak_threshold = np.float(self.gc['peak_threshold'])
        self.spacing_threshold = np.float(self.gc['spacing_threshold'])

        # VNA Sweep
        self.startVNA = -255.5e6
        self.stopVNA = 255.5e6

        self.ui.centralEdit.setText(str(self.center_freq))
        self.ui.startEdit.setText(str(self.startVNA / 1.0e6))
        self.ui.stopEdit.setText(str(self.stopVNA / 1.0e6))
        self.ui.stepEdit.setText(str(self.lo_step / 1.0e6))
        self.ui.nTonesEdit.setText(str(self.Nfreq))

        # Tool bar
        # ROACH status
        self.ui.actionRoach.triggered.connect(self.roach_connection)
        # ROACH network
        self.ui.actionNetwork.triggered.connect(self.roach_network)
        # Synthesizer
        self.ui.actionSynthesizer.triggered.connect(self.roach_synth)
        # Attenuattors
        self.ui.actionRF_Calibration.triggered.connect(self.roach_atten)
        # QDR Calibration
        self.ui.actionQDR_Calibration.triggered.connect(self.qdr_cal)

        # Buttons
        # Roach
        # Roach Settings
        self.ui.firmDir.mousePressEvent = self.chooseFirmPath
        self.ui.vnaDir.mousePressEvent = self.chooseVNAPath
        self.ui.targDir.mousePressEvent = self.chooseTargPath
        self.ui.streamDir.mousePressEvent = self.chooseStreamPath

        self.ui.upFirmBtn.mousePressEvent = self.upload_firmware
        self.ui.synthBtn.mousePressEvent = self.roach_synth
        self.ui.udpConfBtn.mousePressEvent = self.roach_network
        self.ui.udpTestBtn.mousePressEvent = self.test_udp
        self.ui.attBtn.mousePressEvent = self.roach_atten
        self.ui.writeTestBtn.mousePressEvent = self.write_test_comb

        self.ui.plotSweepBtn.mousePressEvent = self.start_plot_VNA
        self.ui.startSweepBtn.mousePressEvent = self.start_VNA_sweep

        # Iniatialising
        self.statusConn = 0
        self.statusFirm = 0
        self.statusSynth = 0
        self.statusAtt = 0
        self.statusNet = 0

        self.s = None
        self.fpga = None

        try:
            self.fpga = casperfpga.CasperFpga(self.roach_ip, timeout=100.)
            icon.addPixmap(QPixmap('./src/icon/ok_icon.png'))
            self.ui.actionRoach_Status.setIcon(icon)
            logging.info("Connected to: " + self.roach_ip)
        except:
            self.fpga = None
            self.statusConn = 1
            logging.info("Roach link is down")

        # Check firmware
        if self.fpga:
            logging.info('Firmware is uploaded')
            if self.fpga.is_running():
                self.ui.upFirmBtn.setStyleSheet("""QWidget {
                                        color: white;
                                        background-color: green
                                        }""")
            else:
                self.statusFirm = 1
        else:
            self.statusFirm = 1

        # UDP socket
        # Run with root permissions
        try:
            self.s = socket(AF_PACKET, SOCK_RAW, htons(3))
            logging.info('Socket is initialised.')
        except:
            logging.error(
                'Socket is not initialised. Permissions are required')

        # Roach interface
        self.ri = roachInterface(self.fpga, self.gc, self.regs, None)

        # GbE interface
        try:
            self.udp = roachDownlink(self.ri, self.fpga, self.gc, self.regs,
                                     self.s, self.ri.accum_freq)
            self.udp.configSocket()
            logging.info('UDP configuration done.')
        except:
            logging.error("UDP connection couldn't be initialised.")

        # Creation of Plot
        self.fig1 = Figure()
        self.addmpl_homodyne(self.fig1)

        # Creation of Plot
        self.fig1 = Figure()
        self.addmpl_vna(self.fig1)

        # To use LATEX in plots
        matplotlib.rc('text', usetex=True)
        matplotlib.rcParams['text.latex.preamble'] = [r"\usepackage{amsmath}"]

        # IPython console
        self.console = EmbedIPython()
        self.console.kernel.shell.run_cell('%pylab qt')

        self.console.execute("cd ./")

        self.ui.TermVBox.addWidget(self.console)

        self.ui.show()
示例#14
0
s = None
fpga = casperfpga.katcp_fpga.KatcpFpga(gc[np.where(gc == 'roach_ppc_ip')[0][0]][1], timeout = 120.)
#fpga = kp.getFPGA()

# UDP socket
s = socket(AF_PACKET, SOCK_RAW, htons(3))
#s.setsockopt(SOL_SOCKET,SO_RCVBUF,buf_size)
#s.bind((gc[np.where(gc=='udp_dest_device')[0][0]][1],3))

# Valon synthesizer instance
valon = valon_synth9.Synthesizer(gc[np.where(gc == 'valon_comm_port')[0][0]][1])
#valon = kp.getValon()
    
# Roach interface
ri = roachInterface(fpga, gc, regs, valon)

# GbE interface
udp = roachDownlink(ri, fpga, gc, regs, s, ri.accum_freq)
udp.configSocket()

# At this point in the main script we go to main_opt

# 0: Test connection to ROACH
result = kp.testConn(fpga)

# 1: Upload firmware
ri.uploadfpg()

# 2: Initialize system & UDP conn
kp.initValon(valon)
示例#15
0
def saveTimestreamDirfile(subfolder, start_chan, end_chan, time_interval):
    """Saves a dirfile containing the I and Q values for a range of channels, streamed
       over a time interval specified by time_interval
       inputs:
           float time_interval: Time interval to integrate over, seconds"""
    # Roach PPC object
    fpga = getFPGA()
    # UDP socket
    s = socket(AF_PACKET, SOCK_RAW, htons(3))
    # Roach interface
    ri = roachInterface(fpga, gc, regs, None)
    # UDP object
    udp = roachDownlink(ri, fpga, gc, regs, s, ri.accum_freq)
    udp.configSocket()
    chan_range = range(start_chan, end_chan + 1)
    data_path = gc[np.where(gc == 'DIRFILE_SAVEPATH')[0][0]][1]
    Npackets = int(np.ceil(time_interval * ri.accum_freq))
    udp.zeroPPS()
    save_path = os.path.join(data_path, subfolder)
    if not os.path.exists(save_path):
        os.makedirs(save_path)
    filename = save_path + '/' + \
               str(int(time.time())) + '-' + time.strftime('%b-%d-%Y-%H-%M-%S') + '.dir'
    print filename
    np.save('last_data_path.npy', filename)
    # make the dirfile
    d = gd.dirfile(filename, gd.CREAT | gd.RDWR | gd.UNENCODED)
    # add fields
    I_fields = []
    Q_fields = []
    for chan in chan_range:
        I_fields.append('I_' + str(chan))
        Q_fields.append('Q_' + str(chan))
        d.add_spec('I_' + str(chan) + ' RAW FLOAT64 1')
        d.add_spec('Q_' + str(chan) + ' RAW FLOAT64 1')
    d.close()
    d = gd.dirfile(filename, gd.RDWR | gd.UNENCODED)
    nfo_I = map(lambda z: filename + "/I_" + str(z), chan_range)
    nfo_Q = map(lambda z: filename + "/Q_" + str(z), chan_range)
    fo_I = map(lambda z: open(z, "ab"), nfo_I)
    fo_Q = map(lambda z: open(z, "ab"), nfo_Q)
    fo_time = open(filename + "/time", "ab")
    fo_count = open(filename + "/packet_count", "ab")
    count = 0
    while count < Npackets:
        ts = time.time()
        try:
            packet, data, header, saddr = udp.parsePacketData()
            if not packet:
                continue
        except TypeError:
            continue
        packet_count = (np.fromstring(packet[-4:], dtype='>I'))
        idx = 0
        for chan in range(start_chan, end_chan + 1):
            I, Q, __ = udp.parseChanData(chan, data)
            fo_I[idx].write(struct.pack('d', I))
            fo_Q[idx].write(struct.pack('d', Q))
            fo_I[idx].flush()
            fo_Q[idx].flush()
            idx += 1
        fo_count.write(struct.pack('L', packet_count))
        fo_count.flush()
        fo_time.write(struct.pack('d', ts))
        fo_time.flush()
        count += 1
    for idx in range(len(fo_I)):
        fo_I[idx].close()
        fo_Q[idx].close()
    fo_time.close()
    fo_count.close()
    d.close()
    return