Wed, 24 Feb 2021 17:55:10 +0100
MicroPython: started adding manual connection capability with device type and port selection.
eric6/MicroPython/MicroPythonDevices.py | file | annotate | diff | comparison | revisions | |
eric6/MicroPython/MicroPythonWidget.py | file | annotate | diff | comparison | revisions |
--- a/eric6/MicroPython/MicroPythonDevices.py Wed Feb 24 16:46:38 2021 +0100 +++ b/eric6/MicroPython/MicroPythonDevices.py Wed Feb 24 17:55:10 2021 +0100 @@ -191,6 +191,7 @@ foundDevices = [] unknownDevices = [] + unknownPorts = [] manualDevices = {} for deviceDict in Preferences.getMicroPython("ManualDevices"): @@ -202,7 +203,7 @@ vid = port.vendorIdentifier() pid = port.productIdentifier() - if vid == 0 and pid == 0: + if not port.isValid(): # no device detected at port continue @@ -244,8 +245,13 @@ unknownDevices.append((vid, pid, port.description())) logging.debug("Unknown device: (0x%04x:0x%04x %s)", vid, pid, port.description()) + else: + desc = port.description() + if not desc: + desc = "Unknown Device" + unknownPorts.append((vid, pid, desc, port.portName())) - return foundDevices, unknownDevices + return foundDevices, unknownDevices, unknownPorts def getDeviceIcon(boardName, iconFormat=True):
--- a/eric6/MicroPython/MicroPythonWidget.py Wed Feb 24 16:46:38 2021 +0100 +++ b/eric6/MicroPython/MicroPythonWidget.py Wed Feb 24 17:55:10 2021 +0100 @@ -258,6 +258,10 @@ self.__fileManagerWidget = None self.__chartWidget = None + self.__unknownPorts = [] + self.__lastPort = None + self.__lastDeviceType = None + if HAS_QTSERIALPORT: self.__interface = MicroPythonCommandsInterface(self) else: @@ -305,7 +309,9 @@ self.deviceInfoLabel.clear() self.deviceTypeComboBox.addItem("", "") - devices, unknownDevices = MicroPythonDevices.getFoundDevices() + devices, unknownDevices, unknownPorts = ( + MicroPythonDevices.getFoundDevices() + ) if devices: self.deviceInfoLabel.setText( self.tr("%n supported device(s) detected.", "", len(devices))) @@ -391,6 +397,10 @@ yesDefault=True) if yes: self.__addUnknownDevices(list(newUnknownDevices)) + + self.__unknownPorts = unknownPorts + if self.__unknownPorts: + self.connectButton.setEnabled(True) def __handlePreferencesChanged(self): """ @@ -457,7 +467,8 @@ vid, pid) self.__device.setButtons() - self.connectButton.setEnabled(bool(deviceType)) + self.connectButton.setEnabled(bool(deviceType) or + bool(self.__unknownPorts)) @pyqtSlot() def on_checkButton_clicked(self): @@ -959,13 +970,15 @@ @rtype str """ portName = self.deviceTypeComboBox.currentData(self.DevicePortRole) - - if Globals.isWindowsPlatform(): - # return it unchanged - return portName + if portName: + if Globals.isWindowsPlatform(): + # return it unchanged + return portName + else: + # return with device path prepended + return "/dev/{0}".format(portName) else: - # return with device path prepended - return "/dev/{0}".format(portName) + return "" def getCurrentBoard(self): """ @@ -994,6 +1007,19 @@ Private method to connect to the selected device. """ port = self.getCurrentPort() + if not port: + # TODO: implement port and device selection dialog + deviceType = "circuitpython" + port = "ttyACM0" + vid = 0 + pid = 0 + + self.deviceIconLabel.setPixmap(MicroPythonDevices.getDeviceIcon( + deviceType, False)) + self.__device = MicroPythonDevices.getDevice(deviceType, self, + vid, pid) + self.__device.setButtons() + if self.__interface.connectToDevice(port): self.__setConnected(True) @@ -1005,8 +1031,8 @@ E5MessageBox.warning( self, self.tr("Serial Device Connect"), - self.tr("""<p>Cannot connect to device at serial port""" - """ <b>{0}</b>.</p>""").format(port)) + self.tr("""<p>Cannot connect to device at serial""" + """ port <b>{0}</b>.</p>""").format(port)) def __disconnectFromDevice(self): """