C#:蓝牙GATT通信。 GattCharacteristic.ValueChanged在某段时间后没有被击中

时间:2015-10-20 16:22:04

标签: c# wpf bluetooth

我正在研究使用GATT进行蓝牙通信的wpf应用程序。我正在使用GattCharacteristic.ValueChanged来处理来自设备的任何值。它有效并且事件处理程序在1分钟后不会被调用。在Windows 8.1中观察到此问题,但在Windows 10中工作。

我是GattCharacteristic成员变量,因此GC不会收集变量。问题仍然存在。

谁能告诉我这里可能存在的潜在问题?

private GattCharacteristic m_DataSenderCharacteristics;
foreach (var service in serviceInfo)
{
var uuid = MjGattDeviceService.UuidFromServiceInformation(service);
//Battery Service
if (uuid.ToString() == BatteryUUID)
{
    var bService = await GattDeviceService.FromIdAsync(service.Id);
    m_Device.batteryService = bService;
}
if (uuid.ToString() == CustomServiceUUID)
{
    m_Device.gattService = await GattDeviceService.FromIdAsync(service.Id);

    Guid controlGUID = new Guid(ControlUUID);
    var controlGattCharacteristics =      m_Device.gattService.GetCharacteristics(controlGUID);
    Byte[] bsdata = new Byte[] { 0x0b, 0x00, 0x02 };
    IBuffer buffUTF8 = CryptographicBuffer.CreateFromByteArray(bsdata);
    GattCommunicationStatus status = await controlGattCharacteristics[0].WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.Notify);

    if (status == GattCommunicationStatus.Unreachable)
    {
        m_Device.isConnected = false;
        nextPage = "Unreachable";
    }
    else if (status == GattCommunicationStatus.Success)
    {
        var ctrlStatus = await controlGattCharacteristics[0].WriteValueAsync(buffUTF8);
        Guid guuid1 = new Guid(DataSenderUUID);
        m_DataSenderCharacteristics = m_Device.gattService.GetCharacteristics(guuid1)[0];

        GattCommunicationStatus notifyStatus = await m_DataSenderCharacteristics.
            WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.Notify);                   

        //This event handler will be called for some 1 minute. After it falls dead
        m_DataSenderCharacteristics[0].ValueChanged += GestureValueChanged;
        if (notifyStatus == GattCommunicationStatus.Success)
        {
            nextPage = "Connected";
        }
    }
}
}

0 个答案:

没有答案