我正在尝试从BLE设备读取传感器数据,但对Unity/C#/HoloLens/UWP完全陌生。
我从 UWP 使用的命名空间:
#if NETFX_CORE
using System;
using Windows.Devices.Bluetooth.Advertisement;
using Windows.Devices.Bluetooth;
#endif
下面是 BluetoothLEAdvertisementWatcher.Received 的事件处理程序:
#if NETFX_CORE
private async void Watcher_Received(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementReceivedEventArgs args)
{
Debug.Log("=Received Advertisement=");
ulong bluetoothAddress = args.BluetoothAddress;
Debug.Log(" BT_ADDR: " + bluetoothAddress);
Debug.Log(" Local name: " + args.Advertisement.LocalName);
Debug.Log(" advertisement type: " + args.AdvertisementType.ToString());
// Throws 'System.IO.FileNotFoundException' in System.Private.CoreLib.ni.dll
BluetoothLEDevice device = await BluetoothLEDevice.FromBluetoothAddressAsync(bluetoothAddress);
}
#endif
我在堆栈跟踪中看到的所有内容都是:
引发的异常:"System.IO.FileNotFoundException" System.Private.CoreLib.ni.dll 系统找不到该文件 指定。(HRESULT的例外:0x80070002(
我不知道如何进一步调试它,或者一般来说有什么问题。
在我的特定情况下,转到系统 -> 设备 (HOLOLENS( 并删除所有以前配对的蓝牙设备可以解决此问题。
就我而言,我在设备列表中只有Hololens的"点击器"。删除后
System.IO.FileNotFoundException
不再被扔掉了,并且
BluetoothLEDevice.FromBluetoothAddressAsync
似乎有效。 答题器不在附近或打开,只是以前(几周前(配对过。
此错误始终可以通过以下方式重现:
- 配对遥控器
- 配对其他 Gatt 设备
调用 BluetoothLEDevice.FromBluetoothAddressAsync 时,System.IO.FileNotFoundException 会再次抛出,即使答题器未配对也是如此。当我从设备列表中删除遥控器时,它再次工作。