UWP 蓝牙通信:bluetoothDevice 对象始终设置为 null

UWP Bluetooth Communication: bluetoothDevice object is always set to null

我尝试让 PC 和 HoloLens 通过蓝牙 RFCOMM 进行通信,所以我正在编写一个 UWP 应用程序。我可以通过设备观察器获取设备信息和 ID。我的问题是这一行:

var bluetoothDevice = await BluetoothDevice.FromIdAsync(deviceInfo.Id);

我的问题是 bluetoothDevice 总是被设置为 null,尽管这不应该。微软在他们的 RfcommChat 示例中对这一行说:

        // If we were unable to get a valid Bluetooth device object,
        // it's most likely because the user has specified that all unpaired devices
        // should not be interacted with.

但我的电脑和我的 HoloLens 已经配对。无论我是用我的电脑执行应用程序并使用 HoloLens 进行连接,还是使用 HoloLens 并使用我的电脑进行连接,我都会遇到同样的错误。

有人可以帮忙吗?

问候 达斯汀

尝试将 FromBluetoothAddressAsync 与仅 found/paired 设备的 MAC 一起使用,因为 Device.Id 可能是错误的或实际未设置。

我发现了我的错误。我忘了在 package.appxmanifest:

的功能中添加蓝牙
<DeviceCapability Name="bluetooth" />
<DeviceCapability Name="bluetooth.rfcomm">
   <Device Id="any">
     <Function Type="serviceId:34B1CF4D-1069-4AD6-89B6-E161D79BE4D8" />
   </Device>
</DeviceCapability>