Tails270
Tails270

Reputation: 23

C# SerialPort.Write is taking a long time to write data

I am trying to write data to an arduino, im sending 70 lots of 6 bytes (so 420 bytes) and i believe that at 9600 baudrate it should take around 40millsec to send correct? but its taking 400millsec to write and im not sure why or how to make it speed up.

The code im using for sending is simply, the additional code is to just make sure it sends in 6 byte sets.

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)
            {
            }
       }
    }
}

Basically i want this to happen as fast as possible since im trying to update hardware in as realtime as possible. Thanks for any help

Upvotes: 0

Views: 1648

Answers (1)

Guffa
Guffa

Reputation: 700910

The baud rate is bits per second, not bytes per second.

420 bytes is 3360 bits, so the raw data takes 3360/9600 = 0.35 seconds to send. So, 400 ms seems very reasonable when the overhead is included.

Upvotes: 2

Related Questions