首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UWP Bluetooth LE API速度很慢

UWP Bluetooth LE API速度很慢
EN

Stack Overflow用户
提问于 2018-07-24 02:26:50
回答 1查看 786关注 0票数 1

我有Windows窗体应用程序引用蓝牙LE的UWP App。我的ESP32创建关贸总协定服务器。Windows应用程序连接到它,但我每秒可以进行7-9次呼叫。我需要至少每秒40个电话。我正在使用Windows App通过FFT分析音频,计算颜色,然后通过蓝牙发送,如下所示:

代码语言:javascript
复制
AT+SPECTRUM="240,200,122";\r\n

这个命令我每秒要发送40次。Wiki说蓝牙LE的速度是0.27 says,这是可以的。芯片之间的距离为50 is +-。为什么选择蓝牙?我也想在notebook和iPhone上使用它。

我正在自己的任务中发送数据:

代码语言:javascript
复制
public class BluetoothTask
{
    Task task;

    CancellationTokenSource tokenSource = new CancellationTokenSource();

    GattCharacteristic gattCharacteristic;

    public AutoResetEvent Signal { get; } = new AutoResetEvent(true);

    public Point3D Color { get; set; } = new Point3D(0, 0, 0);

    public BluetoothThread()
    {
    }

    public void Start(GattCharacteristic characteristic)
    {
        gattCharacteristic = characteristic;

        tokenSource = new CancellationTokenSource();

        task = Task.Factory.StartNew(() => ProcessAsync());
    }

    public void Stop()
    {
        tokenSource.Cancel();
    }

    async Task ProcessAsync()
    {
        DataWriter writer = new DataWriter();

        Stopwatch stopwatch = new Stopwatch();

        int i = 0;

        stopwatch.Start();

        while (true)
        {
            if (tokenSource.Token.IsCancellationRequested)
                break;

            writer.WriteString($"AT+SPECTRUM=\"{(int)Math.Min(Color.X, 255)},{(int)Math.Min(Color.Y, 255)},{(int)Math.Min(Color.Z, 255)}\";\r\n");

            try
            {
                await gattCharacteristic.WriteValueAsync(writer.DetachBuffer());

                i++;

                if(stopwatch.ElapsedMilliseconds >= 1000)
                {
                    Debug.WriteLine($"Bluetooth calls: {i}");

                    i = 0;

                    stopwatch.Restart();
                }
            }
            catch (Exception ex)
            {

            }
        }
    }
}

如果你能给我一些建议,如何加速设备之间的通信,我会很高兴的。哦,顺便说一句,我正在用那颜色的ofc来控制Led条带。

EN

回答 1

Stack Overflow用户

发布于 2018-07-26 07:25:39

增加外设(ESP32)的连接参数,使其频率更高,以提高速度。换句话说,缩短连接间隔。这不是在Windows端,需要在外设端配置。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51485129

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档