c#UWP BluetoothLEDevice.FromIdAsync System.IO.FileNotFoundException
我正在尝试为我的手机编写一个连接到可移动设备的应用程序 设备已配对,我编辑了appxmanifest以启用蓝牙功能 但当我运行应用程序时,下面的代码c#UWP BluetoothLEDevice.FromIdAsync System.IO.FileNotFoundException,c#,win-universal-app,bluetooth-lowenergy,C#,Win Universal App,Bluetooth Lowenergy,我正在尝试为我的手机编写一个连接到可移动设备的应用程序 设备已配对,我编辑了appxmanifest以启用蓝牙功能 但当我运行应用程序时,下面的代码 await BluetoothLEDevice.FromIdAsync(deviceInfo.Id); 结果引发异常:mscorlib.ni.dll中的“System.IO.FileNotFoundException” 有人知道我做错了什么吗 谢谢 var deviceList = await DeviceInformation.FindAllA
await BluetoothLEDevice.FromIdAsync(deviceInfo.Id);
结果引发异常:mscorlib.ni.dll中的“System.IO.FileNotFoundException”
有人知道我做错了什么吗
谢谢
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;
}
}
}
我能够通过使用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;
}
}
}