我正在尝试为我的手机编写一个连接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;
        }
    }
}

最佳答案

我能够通过使用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;
        }
    }
}

关于c# - C#UWP BluetoothLEDevice.FromIdAsync System.IO.FileNotFoundException,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37255074/

10-10 15:35