发现蓝牙设备(Windows)

时间:2016-04-26 11:49:04

标签: c++ windows bluetooth atmel

我尝试在Windows上切换蓝牙设备并遇到一些麻烦。 首先是代码:

WSAQUERYSET wsaq;
HANDLE hLookup;
LPWSAQUERYSET pwsaResults;
DWORD dwSize;
BOOL bHaveName;
BT_ADDR btAddr;
DWORD dwNameSpace;

pwsaResults = (LPWSAQUERYSET)butuh.buf;
dwSize = sizeof(butuh.buf);

ZeroMemory(&wsaq, sizeof(wsaq));
wsaq.dwSize = sizeof(wsaq);
wsaq.dwNameSpace = NS_BTH;
wsaq.lpcsaBuffer = NULL;

if (WSALookupServiceBegin(&wsaq, LUP_CONTAINERS | LUP_FLUSHCACHE, &hLookup) == SOCKET_ERROR)
{
    printf("WSALookupServiceBegin() failed %d (Maybe no BT Device?) \r\n", WSAGetLastError());
    return FALSE;
}

ZeroMemory(pwsaResults, sizeof(WSAQUERYSET));
pwsaResults->dwSize = sizeof(WSAQUERYSET);
pwsaResults->dwNameSpace = NS_BTH;
pwsaResults->lpBlob = NULL;

while (WSALookupServiceNext(hLookup, LUP_RETURN_NAME | LUP_RETURN_ADDR, &dwSize, pwsaResults) == 0)
{
    // to get the remote address, the btAddr field should be properly cast
    btAddr = ((SOCKADDR_BTH *)pwsaResults->lpcsaBuffer->RemoteAddr.lpSockaddr)->btAddr;

    // Verify the returned name
    bHaveName = (pwsaResults->lpszServiceInstanceName) && *(pwsaResults->lpszServiceInstanceName);

    // Some more info
    dwNameSpace = pwsaResults->dwNameSpace;

    wprintf(L"Device Name: %s \n", pwsaResults->lpszServiceInstanceName);
    wprintf(L"Device Address: 0X%012X \n", btAddr);
    wprintf(L"NAP Address: 0X%04X \n", GET_NAP(btAddr));
    wprintf(L"SAP Address: 0X%08X \n", GET_SAP(btAddr));
    wprintf(L"Name Space: 0X%0X \n \n \n", dwNameSpace);

    memcpy(&list+devices, &btAddr, sizeof(btAddr));
    devices++;
}

if (WSALookupServiceEnd(hLookup) != 0)
    printf("FindingBtDevices(): WSALookupServiceEnd(hLookup) failed with error code %ld\n", WSAGetLastError());

我可以毫无问题地发现我的手机或其他电脑,但我尝试使用Atmel的bluetooth devkit并且我无法找到它。 Atmel SAMB11

如果我使用Windows GUI搜索蓝牙设备,找到devkit就没问题了。 知道问题是什么以及如何解决问题?

0 个答案:

没有答案