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

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);
>     }
>
>
>
>
>__________________________________________________________________
>MOHAMED RAOUF
>ICQ#: 44365427
>       Current ICQ status:
>+  More ways to contact me
>__________________________________________________________________
>

_________________________________________________________
There is always a better job for you at Monsterindia.com.
Go now http://monsterindia.rediff.com/jobs