Beispiel #1
0
def discover_devices (duration=8, flush_cache=True, lookup_names=False, lookup_class=False):
    sock = _gethcisock ()
    try:
        results = _bt.hci_inquiry (sock, duration=duration, flush_cache=True, lookup_class=lookup_class)
    except _bt.error:
        sock.close ()
        raise BluetoothError ("error communicating with local "
        "bluetooth adapter")

    if lookup_names:
        pairs = []
        for item in results:
            if lookup_class:
                addr, dev_class = item
            else:
                addr = item
            timeoutms = int (10 * 1000)
            try: 
                name = _bt.hci_read_remote_name (sock, addr, timeoutms)
            except _bt.error:
                # name lookup failed.  either a timeout, or I/O error
                continue
            pairs.append ((addr, name, dev_class) if lookup_class else (addr, name))
        sock.close ()
        return pairs
    else:
        sock.close ()
        return results
Beispiel #2
0
def discover_devices (duration=8, flush_cache=True, lookup_names=False,
                      lookup_class=False, device_id=-1, iac=IAC_GIAC):
    if device_id == -1:
        device_id = _bt.hci_get_route()

    sock = _gethcisock (device_id)
    try:
        results = _bt.hci_inquiry (sock, duration=duration, flush_cache=True,
                                   lookup_class=lookup_class, device_id=device_id,
                                   iac=iac)
    except _bt.error as e:
        sock.close ()
        raise BluetoothError (e.args[0], "Error communicating with local "
        "bluetooth adapter: " + e.args[1])

    if lookup_names:
        pairs = []
        for item in results:
            if lookup_class:
                addr, dev_class = item
            else:
                addr = item
            timeoutms = int (10 * 1000)
            try:
                name = _bt.hci_read_remote_name (sock, addr, timeoutms)
            except _bt.error:
                # name lookup failed.  either a timeout, or I/O error
                continue
            pairs.append ((addr, name, dev_class) if lookup_class else (addr, name))
        sock.close ()
        return pairs
    else:
        sock.close ()
        return results
Beispiel #3
0
def discover_devices(duration=8,
                     flush_cache=True,
                     lookup_names=False,
                     lookup_class=False):
    sock = _gethcisock()
    try:
        results = _bt.hci_inquiry(sock,
                                  duration=duration,
                                  flush_cache=True,
                                  lookup_class=lookup_class)
    except _bt.error:
        sock.close()
        raise BluetoothError("error communicating with local "
                             "bluetooth adapter")

    if lookup_names:
        pairs = []
        for item in results:
            if lookup_class:
                addr, dev_class = item
            else:
                addr = item
            timeoutms = int(10 * 1000)
            try:
                name = _bt.hci_read_remote_name(sock, addr, timeoutms)
            except _bt.error:
                # name lookup failed.  either a timeout, or I/O error
                continue
            pairs.append((addr, name, dev_class) if lookup_class else (addr,
                                                                       name))
        sock.close()
        return pairs
    else:
        sock.close()
        return results
Beispiel #4
0
def lookup_name(address, timeout=10):
    if not is_valid_address(address):
        raise BluetoothError("%s is not a valid Bluetooth address" % address)

    sock = _gethcisock()
    timeoutms = int(timeout * 1000)
    try:
        name = _bt.hci_read_remote_name(sock, address, timeoutms)
    except _bt.error, e:
        # name lookup failed.  either a timeout, or I/O error
        name = None
Beispiel #5
0
def lookup_name(address, timeout=10):
    if not is_valid_address(address):
        raise BluetoothError("%s is not a valid Bluetooth address" % address)

    sock = _gethcisock()
    timeoutms = int(timeout * 1000)
    try:
        name = _bt.hci_read_remote_name(sock, address, timeoutms)
    except _bt.error, e:
        # name lookup failed.  either a timeout, or I/O error
        name = None