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

bt.initwinsock()

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


def discover_devices(duration=8, flush_cache=True, lookup_names=False):
    return bt.discover_devices(flush_cache, lookup_names)


def lookup_name(address, timeout=10):
    if not is_valid_address(address):
        raise ValueError("Invalid Bluetooth address")
    return bt.lookup_name(address)


class BluetoothSocket:
    def __init__(self, proto=RFCOMM, sockfd=None):
        if proto not in [RFCOMM]:
            raise ValueError("invalid protocol")

        if sockfd:
            self._sockfd = sockfd
        else:
            self._sockfd = bt.socket(bt.SOCK_STREAM, bt.BTHPROTO_RFCOMM)
        self._proto = proto

        # used by advertise_service and stop_advertising
        self._sdp_handle = None
Exemplo n.º 2
0
from btcommon import *
import _msbt as bt

bt.initwinsock ()

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

def discover_devices (duration=8, flush_cache=True, lookup_names=False):
    return bt.discover_devices (flush_cache, lookup_names)

def lookup_name (address, timeout=10):
    if not is_valid_address (address): 
        raise ValueError ("Invalid Bluetooth address")
    return bt.lookup_name (address)

class BluetoothSocket:
    def __init__ (self, proto = RFCOMM, sockfd = None):
        if proto not in [ RFCOMM ]:
            raise ValueError ("invalid protocol")

        if sockfd:
            self._sockfd = sockfd
        else:
            self._sockfd = bt.socket (bt.SOCK_STREAM, bt.BTHPROTO_RFCOMM)
        self._proto = proto

        # used by advertise_service and stop_advertising
        self._sdp_handle = None
        self._raw_sdp_record = None

        # used to track if in blocking or non-blocking mode (FIONBIO appears
Exemplo n.º 3
0
import sys
import os
from btcommon import *

def _dbg(*args):
    return
    sys.stderr.write(*args)
    sys.stderr.write("\n")

if sys.platform == "win32":
    import _msbt 
    _msbt.initwinsock ()

    _dbg("trying widcomm")
    have_widcomm = False
    dll = "wbtapi.dll"
    sysroot = os.getenv ("SystemRoot")
    if os.path.exists (dll) or \
       os.path.exists (os.path.join (sysroot, "system32", dll)) or \
       os.path.exists (os.path.join (sysroot, dll)):
        try:
            import widcomm
            if widcomm.inquirer.is_device_ready ():
                # if the Widcomm stack is active and a Bluetooth device on that
                # stack is detected, then use the Widcomm stack
                from widcomm import *
                have_widcomm = True
        except ImportError: 
            pass

    if not have_widcomm: