diff --git a/colourterm/mainwindow.py b/colourterm/mainwindow.py index 0c8978b..ced1fb5 100644 --- a/colourterm/mainwindow.py +++ b/colourterm/mainwindow.py @@ -238,9 +238,17 @@ class MainWindow(QtGui.QMainWindow, UiMainWindow): self.device_closed = True self.device.close() try: - settings.setValue(u'previous-port', self.connect_dialog.get_port()) + port = self.connect_dialog.get_port() + settings.setValue(u'previous-port', port) + if isinstance(port, basestring) and port.startswith('COM'): + try: + # On Windows ports are 0-based, so strip the COM and subtract 1 from the port number + port = int(port[3:]) - 1 + except (TypeError, ValueError): + QtGui.QMessageBox.critical(self, 'Error opening port', 'Error: Port is not valid') + return self.device = Serial( - port=self.connect_dialog.get_port(), + port=port, baudrate=self.connect_dialog.get_baud(), bytesize=self.connect_dialog.get_data_bits(), parity=self.connect_dialog.get_parity(),