【问题标题】:Windows Phone 8.1 - Bluetooth Low Energy and AuthenticationWindows Phone 8.1 - 低功耗蓝牙和身份验证
【发布时间】:2015-01-16 23:24:45
【问题描述】:

我在使用 C# 的低功耗蓝牙设备方面遇到了身份验证问题。

我可以连接到 BLE,从它的服务中读取,但是当我尝试使用这个函数写入时,我收到以下错误:

“该属性需要验证才能读取或写入。(HRESULT 异常:0x80650005)”

我已经配对了设备,正如我所说,我可以从中读取数据。唯一的问题是我需要写的时候。 如果我不配对设备,当我编写它时会自动配对,然后它会给出错误。

    public async static Task<bool> WriteByte(string paramDeviceID, Guid paramService, byte paramValue)
    {
        string debug;
        var Services = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromUuid([UUID HERE]), null);
        GattDeviceService Service = await GattDeviceService.FromIdAsync(paramDeviceID);
        debug = "Using service: " + Services[0].Name; // Service name is correct

        GattCharacteristic gattCharacteristic = Service.GetCharacteristics(paramService)[0];
        var writer = new Windows.Storage.Streams.DataWriter();
        writer.WriteByte(paramValue);

        // Error happens here
        GattCommunicationStatus status = await gattCharacteristic.WriteValueAsync(writer.DetachBuffer()); 

        // This code is never executed, error occurs before
        if (GattCommunicationStatus.Unreachable == status)
        {
            debug = "Write failed";
            return false;
        }

        return true;

    }

有人遇到过同样的问题吗?我该如何解决? 谢谢!

更新 - 当我从手机中移除设备、重置蓝牙设备并将手机与 BLE 设备进行新配对时,此代码完美运行。 然后,每当我从设备断开连接并重新连接时,它都会在我调用 WriteValueAsync 函数时返回错误。即使我在没有使用设备的情况下连接和断开连接......

但是,使用同一设备的 Android 应用,使用该设备没有问题。即使我以前用过。

Windows Phone 8.1 与设备的重新连接似乎有些问题...

【问题讨论】:

  • 问题解决了吗?我处于同样的情况,我真的无法理解这种行为的原因。似乎第一次配对它已连接并经过身份验证,其他时候......没有。
  • 你好 Gnegno,不幸的是,不是。一直没有解决。然而,微软支持似乎知道这个问题,并且正在解决这个问题......“我正在解决一些问题,处理重新连接到与此问题匹配的 BT 设备。我目前没有解决方法,但我的BT 开发团队意识到了这一点,我们正在深入研究。”来源:social.msdn.microsoft.com/Forums/windowsapps/en-US/…
  • 我在 Windows Phone 8.1 上收到此错误,但相同的代码在 Windows 10 Mobile 上运行完美。所以它在 Win 10 中得到了修复,但不幸的是,我们的应用程序无法访问 90% 的 WP 市场:(

标签: c# bluetooth windows-phone-8.1 bluetooth-lowenergy


【解决方案1】:

当我有另一个应用程序连接到设备时出现错误。试试这样:

public async static Task<GattCommunicationStatus> WriteByte(string paramDeviceID, Guid paramService, byte paramValue)
{
    string debug;
    var Services = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromUuid([UUID HERE]), null);
    GattDeviceService Service = await GattDeviceService.FromIdAsync(paramDeviceID);
    debug = "Using service: " + Services[0].Name; // Service name is correct

    GattCharacteristic gattCharacteristic = Service.GetCharacteristics(paramService)[0];
    var writer = new Windows.Storage.Streams.DataWriter();
    writer.WriteByte(paramValue);

    try{
        return GattCommunicationStatus status = await gattCharacteristic.WriteValueAsync(writer.DetachBuffer()); 
    }
    catch()
    {
        debug = "Write failed";
        return GattCommunicationStatus.Unreachable;
    }
}

【讨论】:

  • 尝试了您的代码,但没有... gattCharacteristic.WriteValueAsync 上的相同错误。我已经用新信息更新了我的问题。看起来更像是蓝牙重连的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-28
  • 1970-01-01
  • 1970-01-01
  • 2016-06-14
  • 1970-01-01
相关资源
最近更新 更多