Closed wwj718 closed 6 years ago
the mu-editor is cross-platform Maybe we can use find_microbit()
I had a look at PySerial comports() function for MacOS, and it seems it fills VID and PID automatically. This is all we need to find a microbit.
Also found this implementation:
# Regular expression to match the device id of the micro:bit
RE_VID_PID = re.compile("VID:PID=([0-9A-F]+):([0-9A-F]+)", re.I)
def find_microbit():
"""
Returns the port for the first micro:bit found connected to the computer
running this script. If no micro:bit is found, returns None.
"""
for port, desc, opts in comports():
match = RE_VID_PID.search(opts)
if match:
vid, pid = match.groups()
vid, pid = int(vid, 16), int(pid, 16)
if vid == MICROBIT_VID and pid == MICROBIT_PID:
return port
if sys.platform.startswith('win'):
# No COM port found, so give an informative prompt.
sys.stderr.write('Have you installed the micro:bit driver?\n')
sys.stderr.write('For more details see: {}\n'.format(ARM))
return None
I will try this fix until it fails for someone. Maybe a bad call.
@virtualabs 👍
Make it work with macOS