I'm trying to read sensor data from a BLE Device but am entirely new to Unity / C# / HoloLens / UWP.
My used namespaces from UWP:
#if NETFX_CORE
using System;
using Windows.Devices.Bluetooth.Advertisement;
using Windows.Devices.Bluetooth;
#endif
Here's the event handler for 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
Everything I see in my stacktrace is:
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.ni.dll The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
I do not know how to further debug this, or what's wrong in general.
In my particular case, going to System -> Devices (HOLOLENS) and removing all previously paired bluetooth devices fixes the issue.
In my case, I only had the "Clicker" for the Hololens in the device list. Upon removing it the
System.IO.FileNotFoundException
is not thrown anymore and
BluetoothLEDevice.FromBluetoothAddressAsync
seems to work. The clicker was not anywhere near or on, just had been paired previously (a couple of weeks ago).
This error is always reproducible on my end by:
Upon calling BluetoothLEDevice.FromBluetoothAddressAsync, System.IO.FileNotFoundException is thrown again, even if clicker is unpaired. When I remove the clicker from the devices list, it works again.
User contributions licensed under CC BY-SA 3.0