我正在尝试为连接到BLE设备的手机编写应用程序。
设备已配对,我编辑了appxmanifest以启用蓝牙功能。
但是当我运行应用程序时,下面的代码
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;
}
}
}
答案 0 :(得分: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;
}
}
}