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 USB-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.ui.flash_pushButton.clicked.connect(self.startProgramming) self.ui.checkBox_autoFlash.stateChanged.connect(self.processCheckBox) 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( functools.partial(self.updateProgress, silent=True)) self.thread = threading.Thread(target=self.cycleDongleThread) self.thread.start()
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 USB-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.ui.flash_pushButton.clicked.connect(self.startProgramming) self.ui.checkBox_autoFlash.stateChanged.connect(self.processCheckBox) 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( functools.partial( self.updateProgress, silent=True ) ) self.thread = threading.Thread(target=self.cycleDongleThread) self.thread.start()
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 USB-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.ui.flash_pushButton.clicked.connect(self.startProgramming) self.ui.checkBox_autoFlash.stateChanged.connect(self.processCheckBox) 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( functools.partial(self.updateProgress, silent=True)) self.thread = threading.Thread(target=self.cycleDongleThread) self.thread.start() def robotIdChanged(self, text): if len(text) == 4: self.enableTestButtons() else: self.disableTestButtons() def disableButtons(self): self.ui.flash_pushButton.setEnabled(False) def enableButtons(self): self.ui.flash_pushButton.setEnabled(True) def processCheckBox(self, enabled): if enabled: self.disableButtons() # Start the listening thread self.listenThread = AutoProgramThread(self) self.listenThread.is_alive = True self.listenThread.start() else: self.listenThread.is_alive = False self.listenThread.wait() self.enableButtons() def startProgramming(self, silent=False): serialPort = self.ui.comport_comboBox.currentText() firmwareFile = self.ui.firmwareversion_comboBox.currentText() + '.hex' print('Programming file: ', firmwareFile) try: if firmwareFile.find('32u2') > 0: self.programmer = stk.ATmega32U2Programmer(serialPort) else: self.programmer = stk.ATmegaXXU4Programmer(serialPort) except: if not silent: QtGui.QMessageBox.warning( self, "Programming Exception", 'Unable to connect to programmer at com port ' + serialPort + '. ' + str(e)) traceback.print_exc() return else: raise try: if not silent: self.programmer.programAllAsync(hexfiles=[firmwareFile]) self.progressTimer.start(500) else: self.programmer.programAll(hexfiles=[firmwareFile]) except Exception as e: if not silent: QtGui.QMessageBox.warning( self, "Programming Exception", 'Unable to connect to programmer at com port ' + serialPort + '. ' + str(e)) traceback.print_exc() return else: raise def updateProgress(self, silent=False): # Multiply progress by 200 because we will not be doing verification if silent: try: progress = self.programmer.getProgress() * 100 print(progress) if progress > 100: progress = 100 self.ui.progressBar.setValue(progress) except: pass else: if not self.programmer.isProgramming(): if self.programmer.getLastException() is not None: QtGui.QMessageBox.warning( self, "Programming Exception", str(self.programmer.getLastException())) else: self.ui.progressBar.setValue(100) self.progressTimer.stop() self.enableButtons() def cycleDongleThread(self): daemon = linkbot.Daemon() while self.isRunning: daemon.cycle(2) time.sleep(1) def closeEvent(self, *args, **kwargs): self.isRunning = False
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 USB-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.ui.flash_pushButton.clicked.connect(self.startProgramming) self.ui.checkBox_autoFlash.stateChanged.connect(self.processCheckBox) 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( functools.partial( self.updateProgress, silent=True ) ) self.thread = threading.Thread(target=self.cycleDongleThread) self.thread.start() def robotIdChanged(self, text): if len(text) == 4: self.enableTestButtons() else: self.disableTestButtons() def disableButtons(self): self.ui.flash_pushButton.setEnabled(False) def enableButtons(self): self.ui.flash_pushButton.setEnabled(True) def processCheckBox(self, enabled): if enabled: self.disableButtons() # Start the listening thread self.listenThread = AutoProgramThread(self) self.listenThread.is_alive = True self.listenThread.start() else: self.listenThread.is_alive = False self.listenThread.wait() self.enableButtons() def startProgramming(self, silent=False): serialPort = self.ui.comport_comboBox.currentText() firmwareFile = self.ui.firmwareversion_comboBox.currentText()+'.hex' print('Programming file: ', firmwareFile) try: self.programmer = stk.ATmegaXXU4Programmer(serialPort) except: if not silent: QtGui.QMessageBox.warning(self, "Programming Exception", 'Unable to connect to programmer at com port '+ serialPort + '. ' + str(e)) traceback.print_exc() return else: raise try: if not silent: self.programmer.programAllAsync( hexfiles=[firmwareFile]) self.progressTimer.start(500) else: self.programmer.programAll( hexfiles=[firmwareFile]) except Exception as e: if not silent: QtGui.QMessageBox.warning(self, "Programming Exception", 'Unable to connect to programmer at com port '+ serialPort + '. ' + str(e)) traceback.print_exc() return else: raise def updateProgress(self, silent=False): # Multiply progress by 200 because we will not be doing verification if silent: try: progress = self.programmer.getProgress()*100 print(progress) if progress > 100: progress = 100 self.ui.progressBar.setValue(progress) except: pass else: if not self.programmer.isProgramming(): if self.programmer.getLastException() is not None: QtGui.QMessageBox.warning(self, "Programming Exception", str(self.programmer.getLastException())) else: self.ui.progressBar.setValue(100) self.progressTimer.stop() self.enableButtons() def cycleDongleThread(self): daemon = linkbot.Daemon() while self.isRunning: daemon.cycle(2) time.sleep(1) def closeEvent(self, *args, **kwargs): self.isRunning = False