BluetoothLEDevice on Hololens with Unity

1

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.

c#
unity3d
uwp
bluetooth-lowenergy
hololens
asked on Stack Overflow Sep 9, 2018 by greenteafox • edited Sep 9, 2018 by Programmer

1 Answer

0

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:

  • pairing the clicker
  • pairing the other Gatt device

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.

answered on Stack Overflow Sep 12, 2018 by greenteafox

User contributions licensed under CC BY-SA 3.0