带有 Unity 的 Hololens 上的蓝牙 LED 设备
BluetoothLEDevice on Hololens with Unity
我正在尝试从 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
我在堆栈跟踪中看到的所有内容是:
Exception thrown: 'System.IO.FileNotFoundException' in
System.Private.CoreLib.ni.dll The system cannot find the file
specified. (Exception from HRESULT: 0x80070002)
我不知道如何进一步调试这个,或者一般有什么问题。
在我的特殊情况下,转到系统 -> 设备 (HOLOLENS) 并删除所有以前配对的蓝牙设备可以解决问题。
就我而言,设备列表中只有 "Clicker" 用于 Hololens。删除它后
System.IO.FileNotFoundException
不再抛出
BluetoothLEDevice.FromBluetoothAddressAsync
似乎有效。
唱首歌不在附近或开着,只是 之前(几周前)配对过。
这个错误总是可以通过以下方式重现:
- 配对答题器
- 正在配对其他 Gatt 设备
调用 BluetoothLEDevice.FromBluetoothAddressAsync 后,再次抛出 System.IO.FileNotFoundException,即使答题器未配对。当我从设备列表中删除答题器时,它又可以工作了。
我正在尝试从 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
我在堆栈跟踪中看到的所有内容是:
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.ni.dll The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
我不知道如何进一步调试这个,或者一般有什么问题。
在我的特殊情况下,转到系统 -> 设备 (HOLOLENS) 并删除所有以前配对的蓝牙设备可以解决问题。
就我而言,设备列表中只有 "Clicker" 用于 Hololens。删除它后
System.IO.FileNotFoundException
不再抛出
BluetoothLEDevice.FromBluetoothAddressAsync
似乎有效。 唱首歌不在附近或开着,只是 之前(几周前)配对过。
这个错误总是可以通过以下方式重现:
- 配对答题器
- 正在配对其他 Gatt 设备
调用 BluetoothLEDevice.FromBluetoothAddressAsync 后,再次抛出 System.IO.FileNotFoundException,即使答题器未配对。当我从设备列表中删除答题器时,它又可以工作了。