简体   繁体   English

GattCharacteristic.ValueChanged停止被调用

[英]GattCharacteristic.ValueChanged stops getting called

I am attempting communication with an arduino using an Adafruit Bluefruit LE (a bluetooth 4 module), everything is set up and paired and all that, but I'm having trouble with the ValueChanged event on my GattCharacteristic, it stops firing after somewhere between 30 and 40 times. 我正在尝试使用Adafruit Bluefruit LE(蓝牙4模块)与arduino进行通信,所有内容都已设置并配对,但是我在GattCharacteristic上遇到了ValueChanged事件的问题,它在30之间的某个地方停止发射和40次。

Below is the setup code for this: 以下是此设置代码:

public class Bluetooth
{
    async public void Initialize()
    {
        var devices = await DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromUuid(new Guid("6E400001-B5A3-F393-E0A9-E50E24DCCA9E")), null);

        GattDeviceService firstService = await GattDeviceService.FromIdAsync(devices[0].Id);

        GattCharacteristic rxCharacteristic = firstService.GetCharacteristics(new Guid("6E400003-B5A3-F393-E0A9-E50E24DCCA9E")).First();

        await rxCharacteristic.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.Notify);

        rxCharacteristic.ValueChanged += rxCharacteristicValueChanged;
    }

    private void rxCharacteristicValueChanged(GattCharacteristic characteristic, GattValueChangedEventArgs e)
    {
        Console.WriteLine(e.CharacteristicValue.ToArray()[6]);
    }
}

Is there some kind of buffer I need to clear or something like that? 我需要清除哪种缓冲区或类似的东西? It doesnt look like its buffer related, because If I halve the data being sent, I dont get twice the calls, but I could be wrong. 它看起来不像它的缓冲区相关,因为如果我将发送的数据减半,我不会得到两次调用,但我可能是错的。 The Arduino reports that it is still sending data (through a serial link, I can see that the bluetooth library is still attempting to send data, at any rate. I am not sure how I would verify that the data is actually getting sent) Arduino报告它仍然在发送数据(通过串行链接,我可以看到蓝牙库仍然试图以任何速率发送数据。我不确定如何验证数据实际上是否被发送)

Any help would be appreciated, even suggestions on things to check. 任何帮助将不胜感激,甚至建议检查的事情。

Sounds GC related given your code. 根据您的代码,声音GC相关。

Make firstService or something else a field-level instance. firstService或其他内容设为字段级实例。

This is scoping issue, it seems that the GattCharacteristic object is disposed of after an unknown amount of time... 这是一个范围问题,似乎GattCharacteristic对象在未知的时间后被处理掉...

Make your characteristic a global, problem solved. 让您的特征成为一个全球性的问题。

"You may find that your application stops receiving updates from the device after a period of time. This is a scoping issue where objects are being disposed of that shouldn't. This is because the GattCharacteristic is disposed of before it should be, set the characteristic as a global rather than relying on it being copied in." “您可能会发现您的应用程序在一段时间后停止接收来自设备的更新。这是一个范围问题,其中对象被处理掉的情况不应该。这是因为GattCharacteristic在它应该被处置之前被处理掉,设置为作为一个全球化的特征,而不是依赖于它被复制。“

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM