Using termios/stdio to check for characters

Correo Fernando-ruiz (E-mail) correo at
Wed Jul 11 17:13:20 UTC 2001

Too quick. sorry. Repeating.

> -----Mensaje original-----
> De: OUTWATER ~ KEITH J /5G3110 [mailto:vac4050 at]
> Enviado el: miercoles, 11 de julio de 2001 18:23
> Para: rtems-users at
> Asunto: Using termios/stdio to check for characters
> Greeings all -
> Does anyone know of a way to check a stream to see if
> characters are available
> for input using termios and/or stdio?

Setting NONBLOCK read the filedes and read() returning 0 bytes readed.
//----------------- SOURCE ----------------
  char c;
  fd=open("/dev/name",O_RDWR|_FNBIO,0);  /* O_NDELAY is translated to this
in libio.c */
  if (!read(fd,&c,sizeof(c))) return FALSE;
  return c;
//----------------- EOS ----------------
Am I right? I haven't the source at home. Sorry.

But this file is not opened
with the standard fuunction
 stdin=fopen("/dev/name","r+"); // In this case is not possible.

fnctl() perhaps?

Another question.

The stream io is BUFFERED.
Until the read buffer is not empty your call don't return.
If your line is in canonical mode until the '\r' the read don't return.

//----------------- SOURCE ----------------
 setvbuf(stdin,NULL,_IONBF,0); /* Not buffered*/
//----------------- EOS ----------------
Set the buffer size to 0. After this you can wait for only one character

You will need also setup the serial line in raw mode. (Avoiding the echo and

//----------------- SOURCE ----------------
struct termios term;
if (tcgetattr (fileno(stdin), &term)>=0) {
 term.c_oflag &= ~OPOST;
/* term.c_oflag |= (OPOST|ONLCR);*/ /* But with cr+nl on output */
 term.c_cflag  = CLOCAL | CREAD |(shell_env->tcflag);
 term.c_cc[VMIN]  = 1;
 term.c_cc[VTIME] = 0;
 if (tcsetattr (fileno(stdin), TCSADRAIN, &term) < 0) {
   fprintf(stderr,"shell:cannot set terminal attributes(%s)\n",devname);
//----------------- EOS ----------------

But this a poor solution.

You need set the ioserial driver with an event for reception
and rtems_waitevent(RTMS_EVENT_X,ticstimeout);

Do you want more information about a rtems_serial_driver TERMIOS for a 14550

I can help you if you want.

> Basically, I want to perform a non-blocking check on the
> console port for
> received characters.
> Thanks,
> keith

More information about the users mailing list