1

I am reading data from a sensor connected to a standard RS-232 serial port on a conventional linux kernel (Ubuntu 12.04)

The sensor outputs at 1000Hz. And connects at a baud rate of 115200, 8N1. Each sensor reading is 4 bytes, for a total throughput of 4Kb/s. The pattern of transmission, confirmed by oscilloscope, is a 4-byte burst followed by a near-millisecond pause. The sensor is very, very consistent.

99% of the packets are received with very low latency. However for about 0.5% of the bytes, the serial port read blocks for 2-8ms. Following this block, all the "missed" bytes are read very quickly. This suggests data is, on rare occasions, being buffered.

I have experimented with scheduler priority (nice) and serial port settings (ASYNC_LOW_LATENCY, VMIN, VTIME, raw, non-blocking settings, etc.). None of these seem to have any discernible effect.

Is there anything else I can do to get more consistent serial port reads short of recompiling the kernel or switching to a more real-time OS?

Greg Kogut
  • 19
  • 4
  • *"This suggests data is, on rare occasions, being buffered"* -- Each byte is always buffered (typically twice). The **read()** syscall fetches bytes from a buffer, not directly from the UART's register or FIFO. – sawdust Mar 05 '15 at 08:20
  • Correct. I meant in the context of bytes being queued more quickly than they're being read. My assertion is that 1ms should be more than enough time for read() to pull a byte off that buffer, while I'm seeing that it takes 2-8ms on occasion during which the buffer is growing. – Greg Kogut Mar 05 '15 at 22:55
  • Some of it is very Atmel ARM specific, but maybe there's something useful from https://www.at91.com/viewtopic.php?t=21497 – sawdust Mar 12 '20 at 23:04

2 Answers2

0

An answer can be provided with software or hardware arguments. See for example High delay in RS232 communication on a PXA270 or https://electronics.stackexchange.com/questions/96893/what-can-i-do-to-decrease-the-latency-from-these-serial-ports-which-are-attached.You can try to use low_latency paramlow_latency parameter how is suggest in Minimize Linux Serial Port Latency.

Community
  • 1
  • 1
Mihai8
  • 3,113
  • 1
  • 21
  • 31
  • Thank you, but per my post, I've already tried ASYNC_LOW_LATENCY, both through setserial or through code, to no effect. – Greg Kogut Mar 05 '15 at 23:00
0

I also had this problem when reading to the serial port on my Jetson AGX Orin. I actually tried the PREEMPT rt patch and set the read thread to real-time priority. Most of the time the latency of read() is around 200 us, but occasionally it jumps to 2-4 ms.

I also tried ASYNC_LOW_LATENCY flag, but that doesn't change the results.

Latency Test

Yu He
  • 1