示例#1
0
class PresetHandler(object):

    def __init__(self, ui):
        self.ui = ui
        self.ui.cal_presets_ui.full_2port_button.clicked.connect(self.full_2port_cal)
        self.ui.cal_presets_ui.trl_2port_button.clicked.connect(self.trl_2port_cal)
        self.ui.cal_presets_ui.cal_kit_combo.currentIndexChanged.connect(self.toggle_buttons)
        self.executor = None

    def toggle_buttons(self):
        if self.ui.cal_presets_ui.cal_kit_combo.currentIndex() == 0:
            self.ui.cal_presets_ui.trl_2port_button.setEnabled(True)
        if self.ui.cal_presets_ui.cal_kit_combo.currentIndex() == 1:
            self.ui.cal_presets_ui.trl_2port_button.setEnabled(False)

    def _set_cal_kit(self):
        if self.ui.cal_presets_ui.cal_kit_combo.currentIndex() == 0:
            self.channel.set_cal_kit(1)
        elif self.ui.cal_presets_ui.cal_kit_combo.currentIndex() == 1:
            self.channel.set_cs5()
            self.channel.set_cal_kit(30)

    def _connect(self):
        if self.executor is not None:
            return self.channel # Reuse previously opened object (and socket)
        try:
            chan_number = int(self.ui.cal_presets_ui.channel_combo.currentText())
            self.channels = range(1,chan_number+1)
            ip_port = str(self.ui.vna_ip_field.text()).split(":")
            ip = ip_port[0]
            port = int(ip_port[1])
            self.channel = VnaChannel(ip, port, 1) # Do connection
        except IndexError:
            QtGui.QMessageBox.information(self.ui.centralwidget,
                    "IP no especificado",
                    "Es necesario especificar un IP y puerto en el formato IP:puerto")

    def full_2port_cal(self):
        self._connect()
        def assign_channels(vna):
            for ch in self.channels:
                vna.channel = ch
                vna.set_sparam(1, ch)

        self.channel.channel = 1
        if len(self.channels) == 4:
            self.channel.set_four_channels()
        else:
            self.channel.set_one_channel()
        
        for ch in self.channels:
            self.channel.channel = ch
            self.channel.set_sparam(1, ch)

        for ch in self.channels:
            self.channel.channel = ch
            self._set_cal_kit() # Find and set cal kit
            
        for ch in self.channels:
            self.channel.channel = ch
            self.channel.set_cal_type(CalType.FULL_2PORT)
        
        QtGui.QMessageBox.information(self.ui.centralwidget,"Open", "Conectar open")
        for ch in self.channels:
            self.channel.channel = ch
            self.channel.is_ready()
            self.channel.cal_measure_open(1)
            self.channel.is_ready()
            self.channel.cal_measure_open(2)
            self.channel.is_ready()
        assign_channels(self.channel)
        QtGui.QMessageBox.information(self.ui.centralwidget,"Short", "Conectar short")
        for ch in self.channels:
            self.channel.channel = ch
            self.channel.is_ready()
            self.channel.cal_measure_short(1)
            self.channel.is_ready()
            self.channel.cal_measure_short(2)
            self.channel.is_ready()
        assign_channels(self.channel)
        QtGui.QMessageBox.information(self.ui.centralwidget,"Load", "Conectar load")
        for ch in self.channels:
            self.channel.channel = ch
            self.channel.is_ready()
            self.channel.cal_measure_load(1)
            self.channel.is_ready()
            self.channel.cal_measure_load(2)
            self.channel.is_ready()
        assign_channels(self.channel)
   
        QtGui.QMessageBox.information(self.ui.centralwidget,"Thru", "Conectar thru")
        for ch in self.channels:
            self.channel.channel = ch
            self.channel.is_ready()
            self.channel.cal_measure_thru(1, 2)
            self.channel.is_ready()
            self.channel.cal_measure_thru(2, 1)
            self.channel.is_ready()
        assign_channels(self.channel)


        isolation = QtGui.QMessageBox.question(self.ui.centralwidget,"Isolation", "Calibrar isolation? (opcional)", 
                QtGui.QMessageBox.Yes| QtGui.QMessageBox.No)

        if isolation == QtGui.QMessageBox.Yes:
            QtGui.QMessageBox.information(self.ui.centralwidget,"Isolation", "Conectar load en 1 y 2")
            for ch in self.channels:
                self.channel.channel = ch
                self.channel.is_ready()
                self.channel.cal_measure_isol(1, 2)
                self.channel.is_ready()

            assign_channels(self.channel)

        self.channel.is_ready()
        should_save = QtGui.QMessageBox.question(self.ui.centralwidget, "Guardar?", "Guardar calibracion?",
                QtGui.QMessageBox.Yes| QtGui.QMessageBox.No)

        if should_save == QtGui.QMessageBox.Yes:
            for ch in self.channels:
                self.channel.channel = ch
                self.channel.save_cal()
            
        
    def trl_2port_cal(self):
        self._connect()
        for ch in self.channels:
            self.channel.channel = ch
            self.channel.set_cal_kit(1) # Calkit 85033E
            self.channel.set_cal_type(CalType.TRL_2PORT)
        QtGui.QMessageBox.information(self.ui.centralwidget,"Thru", "Conectar THRU")
        for ch in self.channels:
            self.channel.channel = ch
            self.channel.trl_thru_line(1, 2)
            self.channel.is_ready()
            self.channel.trl_thru_line(2, 1)
            self.channel.is_ready()
        QtGui.QMessageBox.information(self.ui.centralwidget,"Reflect", "Conectar REFLECT")
        
        for ch in self.channels:
            self.channel.channel = ch
            self.channel.trl_reflect(1)
            self.channel.is_ready()
            self.channel.trl_reflect(2)
            self.channel.is_ready()

        QtGui.QMessageBox.information(self.ui.centralwidget,"Line/Match", "Conectar Line Match")
        
        for ch in self.channels:
            self.channel.channel = ch
            self.channel.trl_line_match(1,2)
            self.channel.is_ready()
            self.channel.trl_line_match(2,1)
            self.channel.is_ready()

        should_save = QtGui.QMessageBox.question(self.ui.centralwidget, "Guardar?", "Guardar calibracion?",
                QtGui.QMessageBox.Yes| QtGui.QMessageBox.No)

        if should_save == QtGui.QMessageBox.Yes:
            for ch in self.channels:
                self.channel.channel = ch
                self.channel.save_cal()
示例#2
0
def VnaMeasure(ui, ip, port):
    # Disable button after click

    ui.measure_vna.setEnabled(False)
    ui.left_button.setEnabled(False)
    ui.right_button.setEnabled(False)

    channel = VnaChannel(ip, port, 1) # One channel
    # channel.reset()
    channel.set_four_channels()
    sdata = [] # Clean sdata for each measure
    for idx, spar in enumerate([SParameters.S11, SParameters.S12, SParameters.S21, SParameters.S22]):
        print "Now measuring: " + str(spar)
        channel.set_sweep_type(SweepType.LINEAR)
        channel.channel = idx + 1
        points = str(ui.points_field.text())
        fmat = DataFormat.LOG # By default we use MLOG
        fmat_index = ui.format_combobox.currentIndex()
        formats = [DataFormat.LOG, 
                   DataFormat.LIN, 
                   DataFormat.LIN_PHASE, 
                   DataFormat.PHASE, 
                   DataFormat.GDELAY, 
                   DataFormat.SMITH_LIN_PHASE, 
                   DataFormat.SMITH_LOG_PHASE, 
                   DataFormat.SMITH_RE_IM, 
                   DataFormat.SMITH_R_JX, 
                   DataFormat.SMITH_G_JB]

        fmat = formats[fmat_index]
        
        if ui.center_span_radio.isChecked():
            groupbox = ui.bottom_layout.itemAt(3).widget()
            center_freq = float(groupbox.findChild(QtGui.QLineEdit, "center_field").text())
            span_freq = float(groupbox.findChild(QtGui.QLineEdit, "span_field").text())
            channel.set_center_span(center_freq, span_freq)
            channel.set_traces(1)
            channel.set_points(points)
            channel.set_sparam(1, spar)
            channel.set_format(fmat) # set the selected format
            channel.activate_channel()
            channel.activate_trace(1)
            channel.set_continuous(True)
            
        elif ui.start_stop_radio.isChecked():
            groupbox = ui.bottom_layout.itemAt(3).widget()
            freq_start = float(groupbox.findChild(QtGui.QLineEdit, "freqstart_field").text())
            freq_stop = float(groupbox.findChild(QtGui.QLineEdit, "freqstop_field").text())
            channel.set_start_stop(freq_start, freq_stop)
            channel.set_traces(1)
            channel.set_points(points)
            channel.set_sparam(1, spar)
            channel.set_format(fmat) # set the selected format
            channel.activate_channel()
            channel.activate_trace(1)
            channel.set_continuous(True)

        if ui.autoscale_checkbox.isChecked():
            channel.auto_scale() # Autoscale

        f = str(ui.vna_file_field.text())
        
        retrieve_data(ip, port, f, fmat, channel.executor)
    
    for ch, sparam in zip([1,2,3,4], [SParameters.S11, SParameters.S12, SParameters.S21, SParameters.S22]):
        channel.channel = ch
        channel.set_sparam(1, sparam)

    channel.channel = 1
    channel.executor.close()
    
    # Reenable buttons once measure has finished

    ui.measure_vna.setEnabled(True)
    ui.left_button.setEnabled(True)
    ui.right_button.setEnabled(True)
示例#3
0
def con_alt_measure(smu_params, vna_params, delay, conn_keithley, conn_vna):
    points = smu_params["steps"]
    sweep_time = delay*points
    # Prepare K4200 to measure 
    params.append(smu_params)
    params.append(vna_params)
    ch = smu_params["index"] + 1
    if smu_params["mode"] == "voltage":
        source_mode = SourceMode.VOLTAGE
        source_type = SourceType.VOLTAGE

    if smu_params["mode"] == "current":
        source_mode = SourceMode.CURRENT
        source_type = SourceType.CURRENT

    start = smu_params["start"]
    stop = smu_params["stop"]
    step = smu_params["step"]
    compliance = smu_params["compliance"]
    sweep_type = SweepType.LINEAR # Always linear.

    smu = SMUSweep(ch, source_mode, source_type, start, stop, step, 
            compliance, sweep_type, 'V%s' % ch, "I%s"%ch)
    
    device = K4200(conn_keithley[0], conn_keithley[1])
    device.attach(smu)
    device.configure()
    device.executor.execute_command("SS DT {time}".format(time=delay))
    # device.executor.execute_command("SS HT {time}".format(time=2.2))

    # Prepare VNA to measure

    vna = VnaChannel(conn_vna[0], conn_vna[1], 1)
    vna.set_four_channels()
    vna.set_bus_trigger()

    def measure_vna(vna):
        vlock.acquire()    
        vna.trigger()
        vlock.release()

    def measure_keithley(keithley):
        klock.acquire()
        keithley.measure()
        klock.release()

    for i in range(1,5): # Measure using four channels, once per S parameter
        vna.channel = i
        vna.set_continuous(False)
        vna.set_immediate()
        vna.activate_channel()
        vna.set_traces(1)
        vna.activate_trace(1)
        vna.set_points(points)
        vna.set_format(vna_params["format"])
        vna.set_sparam(1, i) # Assign S11 to ch1, S12 to ch2, S21 to ch3 and S22 to ch4
        vna.set_sweep_time(sweep_time)

        if vna_params["type"] == "center_span":
            vna.set_center_span(vna_params["freq_center"], vna_params["freq_span"])
        elif vna_params["type"] == "start_stop":
            vna.set_center_span(vna_params["freq_start"], vna_params["freq_stop"])

    # Run in different threads to ensure start at the same time
    start_new_thread(measure_vna, (vna,))
    start_new_thread(measure_keithley, (device,))
    start_new_thread(check_vna, (vna,vna_params))
    start_new_thread(check_keithley, (device,smu_params))