[LCP]Serial prog. (again)

Quang Nguyen (Ngo) quang at tapeware.com
Sat Jul 6 01:29:07 UTC 2002


Use poll() or select() to monitor data.

--
Quang


-----Original Message-----
From: linuxcprogramming-admin at lists.linux.org.au
[mailto:linuxcprogramming-admin at lists.linux.org.au]On Behalf Of devraj
sanyal
Sent: Friday, July 05, 2002 6:14 AM
To: linuxcprogramming at lists.linux.org.au
Subject: Re: [LCP]Serial prog. (again)


change /dev/ttyS0 to /dev/tty
and the do while loop will stop after reading the
first charecter. Dont think thats exactly what you
want.
devraj



On Fri, 05 Jul 2002 Mohamed Raouf wrote :
>Here is the code I used for reading from the serial but it's not 
>working
>I also tried it without the "do -- while " (only using the read 
>sentence)
>but it also didn't work . Is there anyone who could help me ?
>
>
># include <stdio.h>
># include <unistd.h>
># include <fcntl.h>
># include <sys/ioctl.h>
># include <sys/wait.h>
># include <string.h>
># include <termios.h>
># include <stdlib.h>
># include <errno.h>
>int
>main(void)
>  {
>  int fd;
>  int n;
>  char recv_char;
>      int m;
>
>  fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
>  if (fd == -1)
>   {
>   perror("open_port: unable to open /dev/ttyS0 - ");
>   }
>  else
>   fcntl (fd, F_SETFL, FNDELAY);
>
>
>    do
>     {
>         /* wait for a char to arrive */
>         m=read(fd, &recv_char, 1);
>     }
>     while (m != 1);
>     printf ( "%c",recv_char);
>     return (recv_char);
>     return (fd);
>     }


________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs SkyScan
service. For more information on a proactive anti-virus service working
around the clock, around the globe, visit http://www.messagelabs.com
________________________________________________________________________




More information about the linuxCprogramming mailing list