def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_MainWindow() self.ui.setupUi(self) self.isRunning = True self.setWindowTitle('Linkbot Jig Main-Board Programmer') # Populate the firmware hex files combobox for f in sorted(findHexFiles()): self.ui.firmwareversion_comboBox.addItem(f) for p in sorted(_getSerialPorts()): self.ui.comport_comboBox.addItem(p) self.disableTestButtons() self.ui.robotid_lineEdit.textChanged.connect(self.robotIdChanged) self.ui.flash_pushButton.clicked.connect(self.startProgramming) self.ui.test_pushButton.clicked.connect(self.runTest) #self.ui.flashtest_pushButton.clicked.connect(self.flashAndTest) self.ui.checkBox_autoFlash.stateChanged.connect(self.processCheckButton) self.ui.progressBar.setValue(0) self.progressTimer = QtCore.QTimer(self) self.progressTimer.timeout.connect(self.updateProgress) self.progressTimerSilent = QtCore.QTimer(self) self.progressTimerSilent.timeout.connect(self.updateProgressSilent) self.autoTest = False try: self.daemon = linkbot.Daemon() except: self.daemon = None
class StartQT4(QtGui.QMainWindow): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_MainWindow() self.ui.setupUi(self) self.isRunning = True self.setWindowTitle('Linkbot Jig Main-Board Programmer') # Populate the firmware hex files combobox for f in sorted(findHexFiles()): self.ui.firmwareversion_comboBox.addItem(f) for p in sorted(_getSerialPorts()): self.ui.comport_comboBox.addItem(p) self.disableTestButtons() self.ui.robotid_lineEdit.textChanged.connect(self.robotIdChanged) self.ui.flash_pushButton.clicked.connect(self.startProgramming) self.ui.test_pushButton.clicked.connect(self.runTest) #self.ui.flashtest_pushButton.clicked.connect(self.flashAndTest) self.ui.checkBox_autoFlash.stateChanged.connect(self.processCheckButton) self.ui.progressBar.setValue(0) self.progressTimer = QtCore.QTimer(self) self.progressTimer.timeout.connect(self.updateProgress) self.progressTimerSilent = QtCore.QTimer(self) self.progressTimerSilent.timeout.connect(self.updateProgressSilent) self.autoTest = False try: self.daemon = linkbot.Daemon() except: self.daemon = None def robotIdChanged(self, text): if len(text) == 4: self.enableTestButtons() else: self.disableTestButtons() def disableTestButtons(self): self.ui.test_pushButton.setEnabled(False) #self.ui.flashtest_pushButton.setEnabled(False) def enableTestButtons(self): self.ui.test_pushButton.setEnabled(True) #self.ui.flashtest_pushButton.setEnabled(True) def disableButtons(self): self.disableTestButtons() self.ui.flash_pushButton.setEnabled(False) def enableButtons(self): self.enableTestButtons() self.ui.flash_pushButton.setEnabled(True) def startProgramming(self): serialPort = self.ui.comport_comboBox.currentText() firmwareFile = self.ui.firmwareversion_comboBox.currentText()+'.hex' try: self.programmer = stk.ATmega128rfa1Programmer(serialPort) except Exception as e: QtGui.QMessageBox.warning(self, "Programming Exception", 'Unable to connect to programmer at com port '+ serialPort + '. ' + str(e)) traceback.print_exc() return # Generate a random ID for the new board self.serialID = "{:04d}".format(random.randint(1000, 9999)) try: self.disableButtons() self.programmer.programAllAsync( serialID=self.serialID, hexfiles=[firmwareFile, bootloader_file], verify=False ) self.progressTimer.start(1000) except Exception as e: QtGui.QMessageBox.warning(self, "Programming Exception", 'Unable to connect to programmer at com port '+ serialPort + '. ' + str(e)) traceback.print_exc() return def startProgrammingSilent(self): print('Trying to start programming...') serialPort = self.ui.comport_comboBox.currentText() firmwareFile = self.ui.firmwareversion_comboBox.currentText()+'.hex' self.programmer = stk.ATmega128rfa1Programmer(serialPort) # Generate a random ID for the new board self.serialID = "{:04d}".format(random.randint(1000, 9999)) self.programmer.serialID = self.serialID self.programmer.programAll( hexfiles=[firmwareFile, bootloader_file], verify=False ) def runTest(self): self.disableButtons() testThread = RobotTestThread(self) testThread.setTestRobotId(self.ui.robotid_lineEdit.text()) testThread.threadFinished.connect(self.testFinished) testThread.threadException.connect(self.testException) testThread.start() def processCheckButton(self, enabled): if enabled: self.disableButtons() # Start the listening thread self.listenThread = AutoProgramThread(self) self.listenThread.is_active = True self.listenThread.start() else: self.listenThread.is_active = False self.listenThread.wait() self.enableButtons() def flashAndTest(self): self.autoTest = True self.startProgramming() def testFinished(self): self.enableButtons() def testException(self, e): QtGui.QMessageBox.warning(self, "Error", "Test failed: " + str(e) ) def updateProgress(self): # Multiply progress by 200 because we will not be doing verification progress = self.programmer.getProgress()*200 if progress > 100: progress = 100 self.ui.progressBar.setValue(progress) if not self.programmer.isProgramming(): if self.programmer.getLastException() is not None: QtGui.QMessageBox.warning(self, "Programming Exception", str(self.programmer.getLastException())) self.progressTimer.stop() if self.daemon: self.daemon.cycle(1) if self.autoTest: self.runTest() ''' timer = QtCore.QTimer(self) timer.timeout.connect(self.runTest) timer.setSingleShot(True) timer.start(8000) ''' else: self.enableButtons() self.autoTest = False def updateProgressSilent(self): # Multiply progress by 200 because we will not be doing verification try: progress = self.programmer.getProgress()*200 if progress > 100: progress = 100 self.ui.progressBar.setValue(progress) except: pass