I am trying to communicate with sensor via UART. I want to use canonical input mode because my sensor sends its data line by line.

For this purpose I set up terminal interface like below:

   structtermios config;

   tcgetattr(_fd, &config)

   /* Canonical Mode Selection */
   config.c_lflag |= ICANON;

   /* Disable Echo, Echo New line */
   config.c_lflag &= ~(ECHO | ECHOE | ECHONL);

   /* Line Settings */
   config.c_cflag |= (CLOCAL | CREAD);/* ignore modem controls */
   config.c_cflag &= ~CSIZE;
   config.c_cflag |= CS8;/* 8-bit characters */
   config.c_cflag &= ~PARENB;/* no parity bit */
   config.c_cflag &= ~CSTOPB;/* only need 1 stop bit */
   config.c_cflag &= ~CRTSCTS;/* no hardware flowcontrol */

   cfsetispeed(&config, B115200);
   cfsetospeed(&config, B115200)
   tcsetattr(_fd, TCSANOW, &config);


After that I called read() function, and I expected to get a line from device.

But I can't get a full line from device. read() function returns even if sensor is not send any NL, EOF characters.

By the way I opened device in nonblocking mode.

Did you try canonical mode before ? I can't find any example. If you tried canonical mode before could you give me any hint about this issue ?

No, I don't think it anyone has every tried cannonical mode.  It may or may not work depending on which driver you are using.  So of the options may be supported some may not be.  Some serial drivers don't support any termios settings, some support a few, none support all of the termios commands.

Consider for example, arch/arm/stm32/stm32_serial.c which probably has most complete termios support.  Some higher-level termios features are also implemented in drivers/serial/serial.c

None of the c_lflags are supported:

  config.c_lflag |= ICANON;
  config.c_lflag &= ~(ECHO | ECHOE | ECHONL); <-- Always disabled

Most ICANON features are NOT supported:

  Input is available character-by-character, not line by line.
  Line editing is disabled (there is no line editting in the drivers)
  Maximum line length does not apply since there is no line buffering.

A few of the c_cflags are supported:

  config.c_cflag |= (CLOCAL | CREAD);  <-- ALWAYS supported
  config.c_cflag &= ~CSIZE; <-- Supported
  config.c_cflag |= CS8;               <-- Supported
  config.c_cflag &= ~PARENB;           <-- Supported
  config.c_cflag &= ~CSTOPB;           <-- Supported
  config.c_cflag &= ~CRTSCTS;          <-- Supported CCTS_OFLOW, CRTS_IFLOW

Baud settings are supported
  cfsetispeed(&config, B115200);
  cfsetospeed(&config, B115200)

Other serial drivers will probably have less termios support.  So I would think that no driver will support CANONICAL mode.


Reply via email to