def initialConnect(self,instrumentAddress):
        #this prevents the user from hammering this function through the GUI
        self.ui.sweepButton.setFocus()
        self.ui.sweepButton.setEnabled(False)

        try:
            #now that the user has selected an address for the keithley, let's connect to it. we'll use the thread safe version of the visa/gpib interface since we have multiple threads here
            self.k = gpib(instrumentAddress,useQueues=True,timeout=None)

            #self.k.task_queue.put(('clear',()))
            #self.sendCmd(':abort')
            self.sendCmd("*rst")
            #self.sendCmd('*cls')
            self.k.task_queue.put(('ask',('*idn?',)))
            try:
                ident = self.k.done_queue.get(block=True,timeout=10)
                self.ui.statusbar.showMessage("Connected to " + ident,self.messageDuration)
            except:
                ident = []

            # let's be sure the firmware and model are what we expect (and what's tested to work)
            modelString = "MODEL 2400"
            firmwareString = "C33"
            if ident.__contains__(modelString):
                if ident.__contains__(firmwareString):
                    self.k.task_queue.put(('ask',(':system:mep:state?',)))
                    isSCPI = self.k.done_queue.get()
                    if isSCPI == '0':
                        if self.initialSetup():
                            self.ui.sweepButton.setEnabled(True)
                            self.ui.sweepButton.setFocus()
                            self.ui.sweepButton.setDefault(True)
                        else:
                            self.closeInstrument()
                            self.ui.statusbar.showMessage("Setup failed")                      
                    else:
                        self.closeInstrument()
                        self.ui.statusbar.showMessage("SCPI comms mode detected")                        
                        msgBox = QMessageBox()
                        msgBox.setWindowTitle("SCPI mode detected. Please sqitch to 488.1 mode.")
                        message488 = \
                            "Perform the following steps to select the 488.1 protocol:\n" + \
                            "1. Press MENU to display the MAIN MENU.\n" + \
                            "2. Place the cursor on COMMUNICATION and press ENTER to display the COMMUNICATIONS SETUP menu.\n" + \
                            "3. Place the cursor on GPIB and press ENTER to display the present GPIB address.\n" + \
                            "4. Press ENTER to display the GPIB PROTOCOL menu.\n" + \
                            "5. Place the cursor on 488.1 and press ENTER.\n" + \
                            "6. Use the EXIT key to back out of the menu structure."
                        msgBox.setText(message488);
                        msgBox.exec_();
                else:
                    self.closeInstrument()
                    self.ui.statusbar.showMessage('{0:s} found, firmware {1:s} not detected. Please upgrade firmware to continue.'.format(modelString,firmwareString))                    
            else:
                self.closeInstrument()
                self.ui.statusbar.showMessage('Could not detect instrument with "{0:s}"'.format(modelString))

        except:
            self.closeInstrument()
            self.ui.statusbar.showMessage("Connection failed")
    def initialConnect(self, instrumentAddress):
        #this prevents the user from hammering this function through the GUI
        self.ui.sweepButton.setFocus()
        self.ui.sweepButton.setEnabled(False)

        try:
            #now that the user has selected an address for the keithley, let's connect to it. we'll use the thread safe version of the visa/gpib interface since we have multiple threads here
            self.k = gpib(instrumentAddress, useQueues=True, timeout=None)

            #self.k.task_queue.put(('clear',()))
            #self.sendCmd(':abort')
            self.sendCmd("*rst")
            #self.sendCmd('*cls')
            self.k.task_queue.put(('ask', ('*idn?', )))
            try:
                ident = self.k.done_queue.get(block=True, timeout=10)
                self.ui.statusbar.showMessage("Connected to " + ident,
                                              self.messageDuration)
            except:
                ident = []

            # let's be sure the firmware and model are what we expect (and what's tested to work)
            modelString = "MODEL 2400"
            firmwareString = "C33"
            if ident.__contains__(modelString):
                if ident.__contains__(firmwareString):
                    self.k.task_queue.put(('ask', (':system:mep:state?', )))
                    isSCPI = self.k.done_queue.get()
                    if isSCPI == '0':
                        if self.initialSetup():
                            self.ui.sweepButton.setEnabled(True)
                            self.ui.sweepButton.setFocus()
                            self.ui.sweepButton.setDefault(True)
                        else:
                            self.closeInstrument()
                            self.ui.statusbar.showMessage("Setup failed")
                    else:
                        self.closeInstrument()
                        self.ui.statusbar.showMessage(
                            "SCPI comms mode detected")
                        msgBox = QMessageBox()
                        msgBox.setWindowTitle(
                            "SCPI mode detected. Please sqitch to 488.1 mode.")
                        message488 = \
                            "Perform the following steps using the buttons on your sourcemeter to select the 488.1 protocol:\n" + \
                            "1. Press MENU to display the MAIN MENU.\n" + \
                            "2. Place the cursor on COMMUNICATION and press ENTER to display the COMMUNICATIONS SETUP menu.\n" + \
                            "3. Place the cursor on GPIB and press ENTER to display the present GPIB address.\n" + \
                            "4. Press ENTER to display the GPIB PROTOCOL menu.\n" + \
                            "5. Place the cursor on 488.1 and press ENTER.\n" + \
                            "6. Use the EXIT key to back out of the menu structure."
                        msgBox.setText(message488)
                        msgBox.exec_()
                else:
                    self.closeInstrument()
                    self.ui.statusbar.showMessage(
                        '{0:s} found, firmware {1:s} not detected. Please upgrade firmware to continue.'
                        .format(modelString, firmwareString))
            else:
                self.closeInstrument()
                self.ui.statusbar.showMessage(
                    'Could not detect instrument with "{0:s}"'.format(
                        modelString))

        except:
            self.closeInstrument()
            self.ui.statusbar.showMessage("Connection failed")
 def run(self):
     try:
         resourceNames = gpib().findInstruments()
     except:
         resourceNames = ["None found"]
     self.foundInstruments.emit(resourceNames)
 def run(self):
     try:
         resourceNames = gpib().findInstruments()
     except:
         resourceNames = ["None found"]
     self.foundInstruments.emit(resourceNames)