Main Site Documentation

Panda II Serial Write Speed


#1

I am writing 512 bytes to the Panda UART port on COM1 and am finding it takes ~40 ms to send. I created a stopwatch and start before the write call and stop on the following line.


 sp.Write(data, 0, data.Length);

Is this expected? Is this dependent on the CPU clock speed? I want to send 512 bytes every 50ms. I am trying to determine if performance on the Panda will be an issue. Thanks.


#2

Baud rate?


#3

SerialPort sp = new SerialPort("COM1", 250000, Parity.None, 8, StopBits.Two);

250,000 is required by the protocol I am using.

I have another thread running which I know is consuming resources, but the sp.write call is taking longer to complete than I expected. I am trying to determine if I am CPU bound or not. I tried increasing the thread priority, but didn’t see much of a difference.


#4

You might want to use RLP if you need strict timing. See RS485 driver on codeshare.


#5

Thank you. I will check the sample out.


#6

Make a simple program which just does the serial send, and measure the time. This will help to determine if
there is an interaction happening with other threads in your program.


#7

I ran the following code and it takes about 23ms to complete. So it appears the sp.Write call is synchronous and not asynchronous. If I increase the baud rate or decrease the bytes sent, the time goes down.

[Code]
public static void Main()

{

OutputPort led = new OutputPort((Cpu.Pin)69, true);
SerialPort sp = new SerialPort(“COM1”, 250000, Parity.None, 8, StopBits.Two);
sp.Open();

// write the data and close the file

byte[] data = new byte[513];
Stopwatch sw = Stopwatch.StartNew();

for (int x = 0; x < (1000); x++)

{

data[0] = 0;
sw.Reset();
sw.Start();

sp.Write(data, 0, data.Length);

sw.Stop();
Debug.Print("Time: " + sw.ElapsedMilliseconds);

}

}


#8

@ Mickpat -

the data rate you measured is about 223000 per second.

the synchronous part may be due to the size of the internal transmit buffer.

I think the test showed your original problem was not serial sent speed.