【问题标题】:C# SerialPort.Write is taking a long time to write dataC# SerialPort.Write 写入数据需要很长时间
【发布时间】:2013-07-14 15:13:13
【问题描述】:

我正在尝试将数据写入 arduino,我发送了 70 批 6 字节(所以 420 字节),我相信在 9600 波特率下它应该需要大约 40 毫秒才能正确发送?但它需要 400 毫秒来编写,我不知道为什么或如何让它加速。

我用于发送的代码很简单,附加代码只是确保它以 6 字节集发送。

private void Send(List<Byte> Data)
{
    if (Running)
    {
        if (_Port.IsOpen)
        {
            try
            {
                int Rem, Div = Math.DivRem(Data.Count, Tester.Length, out Rem);
                for (int cnt = Rem; cnt < Tester.Length; cnt++)
                {
                    Data.Add(255);
                }
                _Port.Write(Data.ToArray(), 0, Data.Count);
            }
            catch (InvalidOperationException)
            {
                _Port.Close();
            }
            catch (IOException)
            {
            }
       }
    }
}

基本上我希望这种情况尽快发生,因为我试图尽可能实时地更新硬件。 感谢您的帮助

【问题讨论】:

    标签: c# performance serial-port communication


    【解决方案1】:

    波特率是每秒位数,而不是每秒字节数。

    420 字节是 3360 位,因此发送原始数据需要 3360/9600 = 0.35 秒。因此,考虑到开销,400 毫秒似乎是非常合理的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-22
      • 1970-01-01
      • 2016-06-14
      • 2020-10-03
      • 2019-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多