示例#1
0
 def _founddevice(self, err, addr, name, devclass, param):
     try:    
         if err == 0:  # no err
             #print "Found device", addr
             
             # PDIS AoResolver returns addres without the colons
             addr = addr[0:2] + ":" + addr[2:4] + ":" + addr[4:6] + ":" + \
                    addr[6:8] + ":" + addr[8:10] + ":" + addr[10:12]
             
             devinfo = (addr.encode("utf-8").upper(),
                        name,
                        _lightbluecommon._joinclass(devclass)) 
             self._founddevices.append(devinfo)
             
             # keep looking for devices
             self._resolver.next()
         else:
             if err == -25:    # KErrEof (no more devices) 
                 # finished discovery
                 self._resolver.close()
                 self._done = True
             else:
                 print "[lightblue] device discovery error (%d)" % err
                 
     except Exception, e:
         # catch all exceptions, the app will crash if exception is raised
         # during callback
         print "Error during _founddevice() callback: "+ str(e)
         
示例#2
0
def gethostclass():
    sock = _gethcisock()
    try:
        try:
            cod = _lightblueutil.hci_read_class_of_dev(sock.fileno(), 1000)
        except IOError, e:
            raise _lightbluecommon.BluetoothError(str(e))
    finally:
        sock.close()

    return _lightbluecommon._joinclass(cod)
示例#3
0
def gethostclass():
    sock = _gethcisock()
    try:
        try:
            cod = _lightblueutil.hci_read_class_of_dev(sock.fileno(), 1000)
        except IOError, e:
            raise _lightbluecommon.BluetoothError(str(e))
    finally:
        sock.close()

    return _lightbluecommon._joinclass(cod)
示例#4
0
    details = __advertised.get(id(sock))
    if details is None:
        raise _lightbluecommon.BluetoothError("no service advertised")
    
    name, servicetype = details
    _socket.bt_advertise_service(name, sock._sock, False, servicetype)

def selectdevice():
    import _lightblueutil
    try:
        result = _lightblueutil.selectDevice()
    except SymbianError, e:
        raise _lightbluecommon.BluetoothError(str(e))
        
    # underlying method returns class of device as tuple, not whole class
    devinfo = (result[0], result[1], _lightbluecommon._joinclass(result[2]))
    return devinfo

def selectservice():
    device = selectdevice()
    if device is None: 
        return None
            
    import appuifw
    services = findservices(addr=device[0])
    choice = appuifw.popup_menu(
        [unicode("%d: %s" % (s[1], s[2])) for s in services], 
        u"Choose service:")
    if choice is None:
        return None
    return services[choice]