tty API

API Reference


This API provides routines to configure serial ports.

Open/Close serial ports

  • le_tty_Open() opens a serial port device and locks it for exclusive use.
fd = le_tty_Open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);

Settings serial ports

  • Setting baud rate is done with le_tty_SetBaudRate(), value available are listed by #tty_Speed_t
  • Getting baud rate is done with le_tty_GetBaudRate(). when le_tty_SetBaudRate() failed with LE_UNSUPPORTED, use le_tty_GetBaudRate() to retrieve the real value sets by the driver.
  • Setting framing on serial port is done with le_tty_SetFraming(). Parity value can be :
    • "N" for No parity
    • "O" for Odd parity
    • "E" for Even parity
  • Setting flow control on serial port is done with le_tty_SetFlowControl(). Flow control options are:
    • LE_TTY_FLOW_CONTROL_NONE - flow control disabled
    • LE_TTY_FLOW_CONTROL_XON_XOFF - software flow control (XON/XOFF)
    • LE_TTY_FLOW_CONTROL_HARDWARE - hardware flow control (RTS/CTS)
  • Setting serial port into terminal mode is done with le_tty_SetCanonical(). it converts EOL characters to unix format, enables local echo, line mode.
  • Setting serial port into raw (non-canonical) mode is done with le_tty_SetRaw(). it disables conversion of EOL characters, disables local echo, sets character mode, read timeouts.

    Different use cases for numChars and timeout parameters in le_tty_SetRaw(int fd,int numChars,int timeout)

    • numChars = 0 and timeout = 0: Read will be completetly non-blocking.
    • numChars = 0 and timeout > 0: Read will be a pure timed read. If the timer expires without data, zero is returned.
    • numChars > 0 and timeout > 0: Read will return when numChar have been transferred to the caller's buffer or when timeout expire between characters.
    • numChars > 0 and timeout = 0: Read will return only when exactly numChars have been transferred to the caller's buffer. This can wait and block indefinitely, when read(fd,buffer,nbytes) is performed and that nbytes is smaller than the numChars setted.

To switch between 'cannonical' and 'raw' mode, just call le_tty_SetCanonical() and le_tty_SetRaw() respectively