Exemple #1
0
class CalHandler(object):

    def __init__(self, ui):
        self.ui = ui
        self.ui.cal_ui.open_button.clicked.connect(self.calibrate_open)
        self.ui.cal_ui.short_button.clicked.connect(self.calibrate_short)
        self.ui.cal_ui.load_button.clicked.connect(self.calibrate_load)
        self.ui.cal_ui.savecal_button.clicked.connect(self.save_cal)
        self.cal_type_selected = False
        self.cal_kit_selected = False
        self.channel = None
        self.cals_done = []

    def _connect_to_vna(self):
        if self.channel is not None:
            return self.channel # Reuse previously opened object (and socket)
        try:
            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 _get_cal_data(self):
        if self.ui.cal_ui.cal_type_combo.currentIndex() == 0:
            cal_type = CalType.OPEN
        elif self.ui.cal_ui.cal_type_combo.currentIndex() == 1:
            cal_type = CalType.SHORT
        elif self.ui.cal_ui.cal_type_combo.currentIndex() == 2:
            cal_type = CalType.THRU
        elif self.ui.cal_ui.cal_type_combo.currentIndex() == 3:
            cal_type = CalType.FULL_2PORT
        elif self.ui.cal_ui.cal_type_combo.currentIndex() == 4:
            cal_type = CalType.FULL_1PORT

        if self.ui.cal_ui.cal_kit_combo.currentIndex() == 0:
            cal_kit = 1 # For 85033E
        
        return {"cal_type": cal_type, "cal_kit": cal_kit} 

    def _disable_buttons(self):
        self.ui.cal_ui.open_button.setEnabled(False)
        self.ui.cal_ui.short_button.setEnabled(False)
        self.ui.cal_ui.load_button.setEnabled(False)
    
    def _selected_port(self):
        return self.ui.cal_ui.port_combo.currentIndex() + 1
       
    def save_cal(self):
        self.channel.save_cal()

    def calibrate_open(self):
        ret = QtGui.QMessageBox.information(self.ui.centralwidget, 
                "Conectar", "Conectar Open", buttons=QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel)
        if ret == QtGui.QMessageBox.Cancel:
            return
                
        def measure():
            self._connect_to_vna()
            self._disable_buttons()
            buttons = [self.ui.cal_ui.open_button, self.ui.cal_ui.short_button, self.ui.cal_ui.load_button]
            self.cals_done.append("open")
            thread.start_new_thread(enable_when_ready, (buttons, self.channel, self.cals_done))
            cal_data = self._get_cal_data()
            if not self.cal_kit_selected:
                self.channel.set_cal_kit(cal_data["cal_kit"])
                self.cal_kit_selected = True
            if not self.cal_type_selected:
                self.channel.set_cal_type(cal_data["cal_type"], self._selected_port())
                self.cal_type_selected = True
            self.channel.cal_measure_open(self._selected_port())

        thread.start_new_thread(measure, ())
        print "Calibrate open"

    def calibrate_short(self):
        ret = QtGui.QMessageBox.information(self.ui.centralwidget, 
                "Conectar", "Conectar Short", buttons=QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel)
        if ret == QtGui.QMessageBox.Cancel:
            return
        
        def measure():
            self._connect_to_vna()
            self._disable_buttons()
            buttons = [self.ui.cal_ui.open_button, self.ui.cal_ui.short_button, self.ui.cal_ui.load_button]
            self.cals_done.append("short")
            thread.start_new_thread(enable_when_ready, (buttons, self.channel, self.cals_done))
            cal_data = self._get_cal_data()

            if not self.cal_kit_selected:
                self.channel.set_cal_kit(cal_data["cal_kit"])
                self.cal_kit_selected = True
            if not self.cal_type_selected:
                self.channel.set_cal_type(cal_data["cal_type"], self._selected_port())
                self.cal_type_selected = True

            self.channel.cal_measure_short(self._selected_port())

        thread.start_new_thread(measure, ())
        print "Calibrate short"

    def calibrate_load(self):
        ret = QtGui.QMessageBox.information(self.ui.centralwidget, 
                "Conectar", "Conectar Load", buttons=QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel)
        if ret == QtGui.QMessageBox.Cancel:
            return
        
        def measure():
            self._connect_to_vna()
            self._disable_buttons()
            buttons = [self.ui.cal_ui.open_button, self.ui.cal_ui.short_button, self.ui.cal_ui.load_button]
            self.cals_done.append("load")
            thread.start_new_thread(enable_when_ready, (buttons, self.channel, self.cals_done))
            cal_data = self._get_cal_data()

            if not self.cal_kit_selected:
                self.channel.set_cal_kit(cal_data["cal_kit"])
                self.cal_kit_selected = True
            if not self.cal_type_selected:
                self.channel.set_cal_type(cal_data["cal_type"], self._selected_port())
                self.cal_type_selected = True
   
            self.channel.cal_measure_load(self._selected_port())
        
        thread.start_new_thread(measure, ())

        print "Calibrate load"
Exemple #2
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()