2016-05-16 70 views
2

我正在嘗試爲我的手機編寫一個應用程序,該應用程序連接到BLE設備。c#UWP BluetoothLEDevice.FromIdAsync System.IO.FileNotFoundException

該設備已配對,我編輯了appxmanifest以啓用藍牙功能。

但是當我運行應用程序,下面的代碼,

await BluetoothLEDevice.FromIdAsync(deviceInfo.Id); 

導致異常拋出:「System.IO.FileNotFoundException」在mscorlib.ni.dll

沒有人有一個想法我做錯了什麼?

謝謝!

var deviceList = await DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromUuid(GattServiceUuids.GenericAccess), null); 
int count = deviceList.Count(); 
if (count > 0) 
{ 
    var deviceInfo = deviceList.Where(x => x.Name == "XC-Tracer").FirstOrDefault(); 
    if (deviceInfo != null) 
    { 
     if (deviceInfo.IsEnabled) 
     { 
      var bleDevice = await BluetoothLEDevice.FromIdAsync(deviceInfo.Id); 
      var deviceServices = bleDevice.GattServices; 
     } 
    } 
} 

回答

1

我能夠通過使用GattDeviceService而不是使用BluetoothLEDevice類來得到這個工作:

var deviceList = await DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromUuid(GattServiceUuids.GenericAccess), null); 
int count = deviceList.Count(); 
if (count > 0) 
{ 
    var deviceInfo = deviceList.Where(x => x.Name == "XC-Tracer").FirstOrDefault(); 
    if (deviceInfo != null) 
    { 
     if (deviceInfo.IsEnabled) 
     { 
      var bleDevice = await GattDeviceService.FromIdAsync(deviceInfo.Id); 
      var deviceServices = bleDevice.GattServices; 
     } 
    } 
}