eric7/MicroPython/MicroPythonDevices.py

branch
eric7
changeset 8508
fbd629e65477
parent 8462
34bb10914b21
child 8762
49d93d0069af
equal deleted inserted replaced
8507:2a22d0880d21 8508:fbd629e65477
221 for deviceDict in Preferences.getMicroPython("ManualDevices"): 221 for deviceDict in Preferences.getMicroPython("ManualDevices"):
222 manualDevices[(deviceDict["vid"], deviceDict["pid"])] = deviceDict 222 manualDevices[(deviceDict["vid"], deviceDict["pid"])] = deviceDict
223 223
224 availablePorts = QSerialPortInfo.availablePorts() 224 availablePorts = QSerialPortInfo.availablePorts()
225 for port in availablePorts: 225 for port in availablePorts:
226 supported = False 226 if port.hasVendorIdentifier() and port.hasProductIdentifier():
227 vid = port.vendorIdentifier() 227 supported = False
228 pid = port.productIdentifier() 228 vid = port.vendorIdentifier()
229 229 pid = port.productIdentifier()
230 if not port.isValid(): 230
231 # no device detected at port 231 for board in SupportedBoards:
232 continue
233
234 for board in SupportedBoards:
235 if (
236 (vid, pid) in SupportedBoards[board]["ids"] or
237 (vid, None) in SupportedBoards[board]["ids"]
238 ):
239 if ( 232 if (
240 board in ("bbc_microbit", "calliope") and 233 (vid, pid) in SupportedBoards[board]["ids"] or
241 (port.description().strip() != 234 (vid, None) in SupportedBoards[board]["ids"]
242 SupportedBoards[board]["port_description"])
243 ): 235 ):
244 # both boards have the same VID and PID 236 if (
245 # try to differentiate based on port description 237 board in ("bbc_microbit", "calliope") and
246 continue 238 (port.description().strip() !=
239 SupportedBoards[board]["port_description"])
240 ):
241 # both boards have the same VID and PID
242 # try to differentiate based on port description
243 continue
244 foundDevices.append((
245 board,
246 port.description(),
247 SupportedBoards[board]["description"],
248 port.portName(),
249 vid,
250 pid,
251 ))
252 supported = True
253 if not supported and (vid, pid) in manualDevices:
254 # check the locally added ones next
255 board = manualDevices[(vid, pid)]["type"]
247 foundDevices.append(( 256 foundDevices.append((
248 board, 257 board,
249 port.description(), 258 port.description(),
250 SupportedBoards[board]["description"], 259 SupportedBoards[board]["description"],
251 port.portName(), 260 port.portName(),
252 vid, 261 vid,
253 pid, 262 pid,
254 )) 263 ))
255 supported = True 264 supported = True
256 if not supported and (vid, pid) in manualDevices: 265 if not supported:
257 # check the locally added ones next 266 if vid and pid:
258 board = manualDevices[(vid, pid)]["type"] 267 if (vid, pid) not in IgnoredBoards:
259 foundDevices.append(( 268 unknownDevices.append((vid, pid, port.description()))
260 board, 269 logging.debug("Unknown device: (0x%04x:0x%04x %s)",
261 port.description(), 270 vid, pid, port.description())
262 SupportedBoards[board]["description"], 271 else:
263 port.portName(), 272 # either VID or PID or both not detected
264 vid, 273 desc = port.description()
265 pid, 274 if not desc:
266 )) 275 desc = QCoreApplication.translate("MicroPythonDevice",
267 supported = True 276 "Unknown Device")
268 if not supported: 277 unknownPorts.append((vid, pid, desc, port.portName()))
269 if vid and pid:
270 if (vid, pid) not in IgnoredBoards:
271 unknownDevices.append((vid, pid, port.description()))
272 logging.debug("Unknown device: (0x%04x:0x%04x %s)",
273 vid, pid, port.description())
274 else:
275 # either VID or PID or both not detected
276 desc = port.description()
277 if not desc:
278 desc = QCoreApplication.translate("MicroPythonDevice",
279 "Unknown Device")
280 unknownPorts.append((vid, pid, desc, port.portName()))
281 278
282 return foundDevices, unknownDevices, unknownPorts 279 return foundDevices, unknownDevices, unknownPorts
283 280
284 281
285 def getDeviceIcon(boardName, iconFormat=True): 282 def getDeviceIcon(boardName, iconFormat=True):

eric ide

mercurial