【问题标题】:BluetoothLEDevice on Hololens with Unity带有 Unity 的 Hololens 上的 BluetoothLEDevice
【发布时间】:2018-09-09 16:23:41
【问题描述】:

我正在尝试从 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)

我不知道如何进一步调试这个,或者一般是什么问题。

【问题讨论】:

  • bluetoothAddress 对象的值是多少?
  • 92823078933695 是 args.BluetoothAddress 所持有的。
  • 您是否在您的项目应用清单中启用了蓝牙功能?
  • 当我从 Unity 构建项目时,我在项目设置中设置了蓝牙作为一项功能。编辑: 在应用清单中
  • 您需要查看thisthis 的帖子。他们应该可以帮助您找到问题。

标签: c# unity3d uwp bluetooth-lowenergy hololens


【解决方案1】:

在我的特定情况下,转到系统 -> 设备 (HOLOLENS) 并删除所有以前配对的蓝牙设备可以解决此问题。

就我而言,设备列表中只有 Hololens 的“Clicker”。删除后,

System.IO.FileNotFoundException

不再被抛出并且

BluetoothLEDevice.FromBluetoothAddressAsync 

似乎有效。 答题器不在附近或在任何地方,只是之前(几周前)配对过。

这个错误总是可以通过以下方式重现:

  • 配对答题器
  • 与其他 Gatt 设备配对

在调用 BluetoothLEDevice.FromBluetoothAddressAsync 时,会再次引发 System.IO.FileNotFoundException,即使点击器未配对。当我从设备列表中删除答题器时,它又可以工作了。

【讨论】:

    猜你喜欢
    • 2018-05-07
    • 2020-02-23
    • 2017-02-16
    • 2018-05-01
    • 1970-01-01
    • 2021-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多