Exemplo n.º 1
0
from bluetooth import *
import bluetooth._msbt as bt

bt.initwinsock()

# ============== SDP service registration and unregistration ============


def discover_devices(duration=8,
                     flush_cache=True,
                     lookup_names=False,
                     lookup_class=False,
                     device_id=-1):
    #this is order of items in C-code
    btAddresIndex = 0
    namesIndex = 1
    classIndex = 2

    try:
        devices = bt.discover_devices(duration=duration,
                                      flush_cache=flush_cache)
    except OSError:
        return []
    ret = list()
    for device in devices:
        item = [
            device[btAddresIndex],
        ]
        if lookup_names:
            item.append(device[namesIndex])
        if lookup_class:
Exemplo n.º 2
0
from bluetooth import *
import bluetooth._msbt as bt

bt.initwinsock ()

# ============== SDP service registration and unregistration ============

def discover_devices (duration=8, flush_cache=True, lookup_names=False,
                      lookup_class=False, device_id=-1):
    #this is order of items in C-code
    btAddresIndex = 0
    namesIndex = 1
    classIndex = 2

    devices = bt.discover_devices(duration=duration, flush_cache=flush_cache)
    ret = list()
    for device in devices:
        item = [device[btAddresIndex],]
        if lookup_names:
            item.append(device[namesIndex])
        if lookup_class:
            item.append(device[classIndex])

        if len(item) == 1: # in case of address-only we return string not tuple
            ret.append(item[0])
        else:
            ret.append(tuple(i for i in item))
    return ret


def read_local_bdaddr():