网站首页
IC库存
IC展台
电子资讯
技术资料
PDF文档
我的博客
IC72论坛
ic72 logo
资料首页最新产品 技术参数 电路图 设计应用 解决方案 代理商查询 IC替换 IC厂商 电子辞典
关键字: 技术文章 PDF资料 IC价格 电路图 代理商查询 IC替换 IC厂商 电子辞典

WINCE APP之搜索蓝牙设备

    对wince应用程序的编写,以用来搜索到周边的蓝牙设备,需要用到下面3个API函数:

    (1)

    INT WSALookupServiceBegin(

    LPWSAQUERYSET pQuerySet,

    DWORD dwFlags,

    LPHANDLE lphLookup

    );

    这个函数主要用途是填充一个返回参数lphLookup,这是一个HANDLE,是给以后的两个函数用的。我们知道WSA开头的一般都是winsock函数,这个也不例外,只不过是它的第一个参数也就是搜索集pQuerySet设置成了蓝牙相关的。WSAQUERYSET结构如下:

    typedef struct _WSAQuerySet {

    DWORD dwSize;

    LPTSTR lpszServiceInstanceName;

    LPGUID lpServiceClassId;

    LPWSAVERSION lpVersion;

    LPTSTR lpszComment;

    DWORD dwNameSpace;

    LPGUID lpNSProviderId;

    LPTSTR lpszContext;

    DWORD dwNumberOfProtocols;

    LPAFPROTOCOLS lpafpProtocols;

    LPTSTR lpszQueryString;

    DWORD dwNumberOfCsAddrs;

    LPCSADDR_INFO lpcsaBuffer;

    DWORD dwOutputFlags;

    LPBLOB lpBlob;

    } WSAQUERYSET, *PWSAQUERYSETW;

    不过对于蓝牙,我们一般这么用:

    WSAQUERYSET btQuerySet;

    memset(&btQuerySet;, 0,sizeof(btQuerySet;));

    btQuerySet.dwSize = sizeof(btQuerySet;);

    btQuerySet.dwNameSpace = NS_BTH;

    btQuerySet.lpcsaBuffer = NULL;

    再接着看下第二个参数dwFlags,它的取值如下:

    LUP_CONTAINERS:

    Specifies that device discovery is to be performed. If this flag is not set, service discovery will be performed instead.

    LUP_RES_SERVICE:

    Searches the local SDP database. Clear this flag to search for services on a peer device.

    这里用的是LUP_CONTAINERS

    If LUP_CONTAINERS is set, SDP performs a device inquiry to find other Bluetooth devices in the area. This function performs the query. The WSALookupServiceNext function retrieves the results one device at a time.

    (2)

    INT WSALookupServiceNext(

    HANDLE hLookup,

    DWORD dwFlags,

    LPDWORD lpdwBufferLength,

    LPWSAQUERYSET pResults

    );

    这个函数就是用上一个函数的hLookup来开始进行实际的搜索,那么到底搜索些什么呢,也就是我们对那些东西感兴趣呢,这就是通过第二个参数dwFlags指定的。其取值如下:

    LUP_RETURN_NAME:

    Performs a name inquiry and sets the results in the pResults lpszServiceInstanceName element.

    LUP_RETURN_ADDR:

    Returns the address of the enumerated remote device in pResults->lpcsaBuffer->RemoteAddr.lpSockaddr.

    LUP_RETURN_BLOB:

    Returns a BthInquiryResult structure in pResults->lpBlob->pBlobData.

    BTHNS_LUP_RESET_ITERATOR:

    Causes the list enumeration to be reset. No data is returned during this call. The next call to this function retrieves information on the first device in the enumeration list.

    BTHNS_LUP_NO_ADVANCE:

    If this flag is not set, the next item in the list is enumerated on the next call to this function. If this flag is set, the next call to this function returns information on the same remote device.

    对于BT,我们主要关心的是NAME用以显示,ADDR用于连接设备并传输数据。

    (3)

    INT WSALookupServiceEnd(

    HANDLE hLookup

    );

    这个函数就显而易见了,关闭搜索句柄。

    以上3个函数的位置:

    Header: Winsock2.h.

    Link Library: Ws2.lib.

热门搜索:2838319 2858043 RBC11A 2856032 TLP810NET PS240810 PS120420 PS480806 BT137S-600D118 01B5001JF PS-415-HG 48VDCSPLITTER LS606M 6NX-6 2839240 2320089 PS-410-HGOEMCC SBB2805-1 2838283 PS120406 ADC128S102CIMTX 2856142 ULTRABLOK 01C5001JF 2856087
COPYRIGHT:(1998-2010) IC72 达普IC芯片交易网
客户服务:service@IC72.com 库存上载:IC72@IC72.com
(北京)联系方式: 在线QQ咨询:点击这里给我发消息 联系电话:010-82614113 传真:010-82614123
京ICP备06008810号-21 京公网安备 11010802032910 号 企业资质