使用Windows 10 BLE API获得自发异常

时间:2017-10-05 08:58:00

标签: c# uwp windows-runtime windows-10 bluetooth-lowenergy

我与BLE设备配对并查询其所有服务&小型测试控制台程序中的特性

我不时会在查询过程中遇到此错误:

Scanning for BLE Devices with service 00008000-0000-1000-8000-0012345678
Finding nearest device
Connecting to MAC CC12345678CF
Pairing...
  Waiting for DevicePairingResult result...
  Waiting for DevicePairingResult result...
Getting info...
  Waiting for GattDeviceServicesResult result...
  Waiting for GattReadResult result...
  Waiting for GattCharacteristicsResult result...
  Async op has Error: System.InvalidOperationException A method was called at an unexpected time. (Exception from HRESULT: 0x8000000E)
  Async op has Error: System.ObjectDisposedException The object has been closed. (Exception from HRESULT: 0x80000013)
  Async op has Error: System.ObjectDisposedException The object has been closed. (Exception from HRESULT: 0x80000013)
  Async op has Error: System.ObjectDisposedException The object has been closed. (Exception from HRESULT: 0x80000013)
Unpairing...
System.NullReferenceException: Object reference not set to an instance of an object.
   at UWPWrapper.BLE.DeviceLister.ListServices(GattDeviceService[] services, Int32 level) in UWPWrapper\UWPWrapper\BLE\DeviceLister.cs:line 96

这一行只是if-case,但它似乎发生在for循环和许多其他地方。

 var descResult = chr.GetDescriptorsAsync().Wait();
 if (descResult.Status != GattCommunicationStatus.Success)
 {
   sb.AppendLine($"{indent}    No descriptors: {descResult.Status}");
 }

在我使用它们的过程中,似乎正在处理我正在访问的对象,因为虽然我一直在保留引用,但我在真正奇怪的地方出错了。

其他问题指向此(收听GATTCharacteristics.ValueChanged事件)。知道如何解决这个问题吗?

FWIW,我正在编写一个简单的C#桌面应用程序,但使用的是WinRT API包装器。除了这个问题,它似乎工作得很好。

0 个答案:

没有答案