Skip to content

Conversation

@wwj718
Copy link
Contributor

@wwj718 wwj718 commented Aug 15, 2018

Make it work with macOS

Make it work with macOS
@wwj718
Copy link
Contributor Author

wwj718 commented Aug 15, 2018

the mu-editor is cross-platform
Maybe we can use find_microbit()

@virtualabs
Copy link
Owner

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 virtualabs merged commit 2d85b0e into virtualabs:master Aug 15, 2018
@wwj718
Copy link
Contributor Author

wwj718 commented Aug 15, 2018

@virtualabs 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants