UWP蓝牙通信:Bluetooth设备对象始终设置为空

UWP蓝牙通信:Bluetooth设备对象始终设置为空,bluetooth,uwp,null,hololens,rfcomm,Bluetooth,Uwp,Null,Hololens,Rfcomm,我尝试让PC和HoloLens通过蓝牙RFCOMM进行通信,所以我正在编写一个UWP应用程序。我可以通过设备监视程序获取设备信息和id。我的问题是这一行: var bluetoothDevice = await BluetoothDevice.FromIdAsync(deviceInfo.Id); // If we were unable to get a valid Bluetooth device object, // it's most likely be

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

var bluetoothDevice = await BluetoothDevice.FromIdAsync(deviceInfo.Id);
        // 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.
我的问题是bluetoothDevice总是设置为null,尽管不应该设置为null。微软在其RfcommChat示例中表示:

var bluetoothDevice = await BluetoothDevice.FromIdAsync(deviceInfo.Id);
        // 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并使用我的电脑连接,我都会遇到同样的错误

有人能帮忙吗

问候
Dustin

尝试使用FromBluetoothAddressAsync与刚找到/配对设备的MAC,而不是因为设备。Id可能错误或未实际设置。

我发现了错误。我忘了在package.appxmanifest的功能中添加蓝牙:

<DeviceCapability Name="bluetooth" />
<DeviceCapability Name="bluetooth.rfcomm">
   <Device Id="any">
     <Function Type="serviceId:34B1CF4D-1069-4AD6-89B6-E161D79BE4D8" />
   </Device>
</DeviceCapability>


deviceInfo.Id
是否来自
DeviceWatcher
?你能展示更多关于观察者的信息吗?如果你已经解决了你的问题,请稍后访问此线程的方便人士接受,谢谢理解。