[LCP]Serial prog. (again)

Mohamed Raouf mohamed.raouf at link.net
Fri Jul 5 20:06:06 UTC 2002


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 
__________________________________________________________________

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.linux.org.au/pipermail/linuxcprogramming/attachments/20020705/ee553e00/attachment.htm 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/octet-stream
Size: 105 bytes
Desc: not available
Url : http://lists.linux.org.au/pipermail/linuxcprogramming/attachments/20020705/ee553e00/attachment.obj 


More information about the linuxCprogramming mailing list