Skip to content

UART — read line to delimiter (uart_read_line)

What it does: Reads data from the UART until it finds the specified end of line or until a timeout occurs.

uart_read_line

Inputs

  • Field ending: line separator ("\r\n", "\n", "\r").
  • timeout: maximum wait in milliseconds.

Output

  • Line text without trailing delimiter.
  • None if the line is not loaded by the timeout.

When to use it

  • For reading text logs line by line (AT commands, CSV, logs).
  • When the counterparty sends data ending in CR/LF.

Tips and pitfalls

  • Choose the correct delimiter according to the opponent, otherwise you will often get timeouts.
  • The function uses an internal buffer between calls, so it can compose split messages.

Generated Python example

line = read_line(uart1, "\n", 1000)