[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Using termios/stdio to check for characters



Too quick. sorry. Repeating.

> -----Mensaje original-----
> De: OUTWATER ~ KEITH J /5G3110 [mailto:vac4050 at tueng.rsc.raytheon.com]
> Enviado el: miercoles, 11 de julio de 2001 18:23
> Para: rtems-users at oarcorp.com
> 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.
etc...

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

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

//----------------- SOURCE ----------------
struct termios term;
if (tcgetattr (fileno(stdin), &term)>=0) {
 term.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
 term.c_oflag &= ~OPOST;
/* term.c_oflag |= (OPOST|ONLCR);*/ /* But with cr+nl on output */
 term.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
 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
UART?

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