Windows runtime DeviceInformation::FindAllAsync无法找到具有RFCOMM服务ID的设备

Windows runtime DeviceInformation::FindAllAsync无法找到具有RFCOMM服务ID的设备,windows-runtime,windows-phone-8.1,rfcomm,Windows Runtime,Windows Phone 8.1,Rfcomm,我想要一个带有两个Windows Phone的简单客户端/服务器设置,我使用以下代码来设置服务器: auto providerTask = create_task(RfcommServiceProvider::CreateAsync(RfcommServiceId::FromUuid(GetServiceGUID()))); providerTask.then([this](RfcommServiceProvider^ p) -> task < void > { th

我想要一个带有两个Windows Phone的简单客户端/服务器设置,我使用以下代码来设置服务器:

auto providerTask = create_task(RfcommServiceProvider::CreateAsync(RfcommServiceId::FromUuid(GetServiceGUID())));

providerTask.then([this](RfcommServiceProvider^ p) -> task < void >
{
    this->provider = p;

    this->listener = ref new StreamSocketListener();
    listener->ConnectionReceived += ref new Windows::Foundation::TypedEventHandler < Windows::Networking::Sockets::StreamSocketListener ^,
        Windows::Networking::Sockets::StreamSocketListenerConnectionReceivedEventArgs ^ >
        (this, &ConnectionManager::OnConnectionReceived);

    return create_task(listener->BindServiceNameAsync(provider->ServiceId->AsString())).then([this]()
    {
        this->provider->StartAdvertising(listener);
    });

}).then([](task<void> t)
{
    //handle exceptions at the end of the chain
    try
    {
        t.get();
    }
    catch (Platform::Exception^ ex)
    {
        if (ex->HResult == 0x9000000F)
        {
            OutputDebugString(L"Bluetooth is disabled.\n");
        }
        else throw ex;
    }
});

对FindAllAsync的调用始终返回空集合,即使两个设备在设置中显示为成对。但是,如果在设置服务器和稍后枚举设备时使用RfcommServiceId::ObexObjectPush而不是FromUuid,则效果很好。有人知道为什么会发生这种情况吗?

在这两种情况下,AQS选择器字符串是什么样子的

问题在于:

  • 选择器与系统上的接口意外不匹配
  • 基本上,过滤器用于匹配当前处于KM PnP状态的设备接口上的属性。如果接口的属性与选择器中逻辑请求的属性匹配,则会将其添加到设备信息集合中

    可能尝试不带选择器的FindAllAsync,然后查看KM PnP当前正在枚举哪些接口。请求选择器中的属性。一旦您看到了您认为应该看到的接口,从逻辑上找出它与选择器不匹配的原因

  • 设备未配对
  • 如果设备没有配对,那么就不会有任何devnode或接口来表示它。因此,FindAllAsync无法发现它

  • 设备已配对,但没有您认为它具有的配置文件
  • 蓝牙总线驱动程序将仅为其理解的配置文件创建PnP状态。FindAllAsync需要PnP状态才能找到它。RFCOMM是一个基本的,所以它应该可以工作

    无论如何,从编写一些测试代码开始,如1所述。这会给你一些信息,让你进一步调查

    另外,请检查Windows.Devices.Enumeration的新Windows 10 API更改。有新的方法可以发现蓝牙设备


    -山姆

    这更有帮助吗?不过,我想进行更多的调查。在这两种情况下,AQS选择器字符串是什么样子的?问题是:选择器与系统上的接口不匹配。过滤器用于匹配当前处于KM PnP状态的设备接口上的属性。如果接口的属性与选择器中逻辑请求的属性匹配,则会将其添加到设备信息集合中。
    auto query = RfcommDeviceService::GetDeviceSelector(RfcommServiceId::FromUuid(GetServiceGUID()));
    
    create_task(DeviceInformation::FindAllAsync(query))
        .then([this](DeviceInformationCollection^ services)
    {
        if (services->Size > 0)
        {
            OutputDebugString(L"We've found a server!\n");
            OutputDebugString(services->First()->Current->Name->Data());
        }
    });