pyOCD/board/mbed_board.py
def chooseBoard(dap_class=DAPAccess, blocking=True, return_first=False,
                    board_id=None, target_override=None, frequency=1000000,
                    init_board=True):
        """
        Allow you to select a board among all boards connected
        """
        all_mbeds = MbedBoard.getAllConnectedBoards(dap_class, True, blocking,
                                                    target_override, frequency)

        # If a board ID is specified remove all other boards
        if board_id != None:
            board_id = board_id.lower()
            new_mbed_list = []
            for mbed in all_mbeds:
                if board_id in mbed.unique_id.lower():
                    new_mbed_list.append(mbed)
            if len(new_mbed_list) > 1:
                print(colorama.Fore.RED + "More than one board matches board ID '%s'" % board_id + colorama.Style.RESET_ALL)
                all_mbeds = sorted(all_mbeds, key=lambda x:x.getInfo())
                for mbed in all_mbeds:
                    head, sep, tail = mbed.unique_id.lower().rpartition(board_id)
                    highlightedId = head + colorama.Fore.RED + sep + colorama.Style.RESET_ALL + tail
                    print "%s | %s" % (
                        mbed.getInfo().encode('ascii', 'ignore'),
                        highlightedId)
                return None
            all_mbeds = new_mbed_list

        # Return if no boards are connected
        if all_mbeds == None or len(all_mbeds) <= 0:
            if board_id is None:
                print("No connected boards")
            else:
                print("Board %s is not connected" % board_id)
            return None # No boards to close so it is safe to return

        # Select first board
        if return_first:
            all_mbeds = all_mbeds[0:1]

        # Ask use to select boards if there is more than 1 left
        if len(all_mbeds) > 1:
            all_mbeds = sorted(all_mbeds, key=lambda x:x.getInfo())
            print colorama.Fore.BLUE + "## => Board Name | Unique ID"
            print "-- -- ----------------------"
            for index, mbed in enumerate(all_mbeds):
                print colorama.Fore.GREEN + "%2d => %s | %s" % (
                    index, mbed.getInfo().encode('ascii', 'ignore'),
                    colorama.Fore.CYAN + mbed.unique_id)
            print colorama.Fore.RED + " q => Quit"
            while True:
                print colorama.Style.RESET_ALL
                print "Enter the number of the board to connect:"
                line = raw_input("> ")
                valid = False
                if line.strip().lower() == 'q':
                    return None
                try:
                    ch = int(line)
                    valid = 0 <= ch < len(all_mbeds)
                except ValueError:
                    pass
                if not valid:
                    print colorama.Fore.YELLOW + "Invalid choice: %s\n" % line
                    for index, mbed in enumerate(all_mbeds):
                        print colorama.Fore.GREEN + "%d => %s" % (index, mbed.getInfo())
                    print colorama.Fore.RED + "q => Exit"
                else:
                    break
            all_mbeds = all_mbeds[ch:ch + 1]

        assert len(all_mbeds) == 1
        mbed = all_mbeds[0]
        mbed.link.open()
        if init_board:
            try:
                mbed.init()
            except:
                mbed.link.close()
                raise
        return mbed

        Allow you to select a board among all boards connected
        
Allow you to select a board among all boards connected
Allow you to select a board among all boards connected
def chooseBoard(dap_class=DAPAccess, blocking=True, return_first=False,
                    board_id=None, target_override=None, frequency=1000000,
                    init_board=True):
        all_mbeds = MbedBoard.getAllConnectedBoards(dap_class, True, blocking,
                                                    target_override, frequency)
        if board_id != None:
            board_id = board_id.lower()
            new_mbed_list = []
            for mbed in all_mbeds:
                if board_id in mbed.unique_id.lower():
                    new_mbed_list.append(mbed)
            if len(new_mbed_list) > 1:
                print(colorama.Fore.RED + "More than one board matches board ID '%s'" % board_id + colorama.Style.RESET_ALL)
                all_mbeds = sorted(all_mbeds, key=lambda x:x.getInfo())
                for mbed in all_mbeds:
                    head, sep, tail = mbed.unique_id.lower().rpartition(board_id)
                    highlightedId = head + colorama.Fore.RED + sep + colorama.Style.RESET_ALL + tail
                    print "%s | %s" % (
                        mbed.getInfo().encode('ascii', 'ignore'),
                        highlightedId)
                return None
            all_mbeds = new_mbed_list
        if all_mbeds == None or len(all_mbeds) <= 0:
            if board_id is None:
                print("No connected boards")
            else:
                print("Board %s is not connected" % board_id)
            return None 
        if return_first:
            all_mbeds = all_mbeds[0:1]
        if len(all_mbeds) > 1:
            all_mbeds = sorted(all_mbeds, key=lambda x:x.getInfo())
            print colorama.Fore.BLUE + "## => Board Name | Unique ID"
            print "-- -- ----------------------"
            for index, mbed in enumerate(all_mbeds):
                print colorama.Fore.GREEN + "%2d => %s | %s" % (
                    index, mbed.getInfo().encode('ascii', 'ignore'),
                    colorama.Fore.CYAN + mbed.unique_id)
            print colorama.Fore.RED + " q => Quit"
            while True:
                print colorama.Style.RESET_ALL
                print "Enter the number of the board to connect:"
                line = raw_input("> ")
                valid = False
                if line.strip().lower() == 'q':
                    return None
                try:
                    ch = int(line)
                    valid = 0 <= ch < len(all_mbeds)
                except ValueError:
                    pass
                if not valid:
                    print colorama.Fore.YELLOW + "Invalid choice: %s\n" % line
                    for index, mbed in enumerate(all_mbeds):
                        print colorama.Fore.GREEN + "%d => %s" % (index, mbed.getInfo())
                    print colorama.Fore.RED + "q => Exit"
                else:
                    break
            all_mbeds = all_mbeds[ch:ch + 1]
        assert len(all_mbeds) == 1
        mbed = all_mbeds[0]
        mbed.link.open()
        if init_board:
            try:
                mbed.init()
            except:
                mbed.link.close()
                raise
        return mbed
def chooseBoard ( dap_class = DAPAccess , blocking = True , return_first = False , board_id = None , target_override = None , frequency = 1000000 , init_board = True ) : all_mbeds = MbedBoard . getAllConnectedBoards ( dap_class , True , blocking , target_override , frequency ) if board_id != None : board_id = board_id . lower ( ) new_mbed_list = [ ] for mbed in all_mbeds : if board_id in mbed . unique_id . lower ( ) : new_mbed_list . append ( mbed ) if len ( new_mbed_list ) > 1 : print ( colorama . Fore . RED + "More than one board matches board ID '%s'" % board_id + colorama . Style . RESET_ALL ) all_mbeds = sorted ( all_mbeds , key = lambda x : x . getInfo ( ) ) for mbed in all_mbeds : head , sep , tail = mbed . unique_id . lower ( ) . rpartition ( board_id ) highlightedId = head + colorama . Fore . RED + sep + colorama . Style . RESET_ALL + tail print "%s | %s" % ( mbed . getInfo ( ) . encode ( 'ascii' , 'ignore' ) , highlightedId ) return None all_mbeds = new_mbed_list if all_mbeds == None or len ( all_mbeds ) <= 0 : if board_id is None : print ( "No connected boards" ) else : print ( "Board %s is not connected" % board_id ) return None if return_first : all_mbeds = all_mbeds [ 0 : 1 ] if len ( all_mbeds ) > 1 : all_mbeds = sorted ( all_mbeds , key = lambda x : x . getInfo ( ) ) print colorama . Fore . BLUE + "## => Board Name | Unique ID" print "-- -- ----------------------" for index , mbed in enumerate ( all_mbeds ) : print colorama . Fore . GREEN + "%2d => %s | %s" % ( index , mbed . getInfo ( ) . encode ( 'ascii' , 'ignore' ) , colorama . Fore . CYAN + mbed . unique_id ) print colorama . Fore . RED + " q => Quit" while True : print colorama . Style . RESET_ALL print "Enter the number of the board to connect:" line = raw_input ( "> " ) valid = False if line . strip ( ) . lower ( ) == 'q' : return None try : ch = int ( line ) valid = 0 <= ch < len ( all_mbeds ) except ValueError : pass if not valid : print colorama . Fore . YELLOW + "Invalid choice: %s\n" % line for index , mbed in enumerate ( all_mbeds ) : print colorama . Fore . GREEN + "%d => %s" % ( index , mbed . getInfo ( ) ) print colorama . Fore . RED + "q => Exit" else : break all_mbeds = all_mbeds [ ch : ch + 1 ] assert len ( all_mbeds ) == 1 mbed = all_mbeds [ 0 ] mbed . link . open ( ) if init_board : try : mbed . init ( ) except : mbed . link . close ( ) raise return mbed
Allow you to select a board among all boards connected
Allow you to select a board among all boards connected
"""
        Allow you to select a board among all boards connected
        """ # If a board ID is specified remove all other boards # Return if no boards are connected # No boards to close so it is safe to return # Select first board # Ask use to select boards if there is more than 1 left
dap_class
blocking
return_first
board_id
target_override
frequency
init_board