<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><DIV></DIV>
<DIV>hello All,</DIV>
<DIV>  i am very new in Linux , and i made a small program in C that jst sends and tries to receive character from serial port. </DIV>
<DIV>  it is working fine for sending, but not receiving character from other end .. on other end Windows Xp running.  Read() function retuns error</DIV>
<DIV>  no = 11, i m putting my small code, </DIV>
<DIV>        plz help  me ...</DIV>
<DIV>thank in advance</DIV>
<DIV> </DIV>
<DIV>CODE:</DIV>
<DIV> </DIV>
<DIV>#include <stdio.h> /* Standard input/output definitions */<BR>#include <string.h> /* String function definitions */<BR>#include <unistd.h> /* UNIX standard function definitions */<BR>#include <fcntl.h> /* File control definitions */<BR>#include <errno.h> /* Error number definitions */<BR>#include <termios.h> /* POSIX terminal control definitions */</DIV>
<DIV><BR>int readport(int fd, char *result) <BR>{<BR> int iIn = read(fd, result, 254);<BR> result[iIn-1] = 0x00;<BR> if (iIn < 0) {<BR>  <BR>   printf("SERIAL EAGAIN ERROR\n");<BR>   printf("\nerro NO =%d\n",errno);<BR>   printf("SERIAL read error %d-----> %s\n", errno, strerror(errno));<BR>   return 0;<BR>        }<BR>                     <BR> return 1;<BR>}</DIV>
<DIV> </DIV>
<DIV><BR>main()<BR>{<BR>int fd;<BR>int nread;<BR>char c;<BR>char bufptr[5];<BR>char buffer[5];<BR>buffer[0]= 'S';<BR>buffer[1]= 'S';<BR>buffer[2]= 'S';<BR>buffer[3]= 'S';<BR>buffer[4]= 'S';<BR>int i;<BR>char sResult[254];<BR>struct termios options;</DIV>
<DIV>// buffer = "Sorry";</DIV>
<DIV>fd = open("/dev/ttyS0",O_RDWR|O_NOCTTY|O_NDELAY);</DIV>
<DIV> if (fd == -1)<BR> {<BR> printf("\n\n\t\t Sorry Yaar Port Nahi Khul Raha \n\n\n");<BR> return 1;<BR> }<BR> else<BR> {<BR> printf("\n\n\t\t Port Khul gaya.... \n\n\n");<BR> fcntl(fd, F_SETFL, 0);<BR> }</DIV>
<DIV>tcgetattr(fd, &options);<BR>cfsetispeed(&options, B9600);<BR>cfsetospeed(&options, B9600);<BR>options.c_cflag |= (CLOCAL | CREAD);</DIV>
<DIV> options.c_cflag &= ~PARENB;<BR> options.c_cflag &= ~CSTOPB;<BR> options.c_cflag &= ~CSIZE;<BR> options.c_cflag |= CS8;</DIV>
<DIV>tcsetattr(fd, TCSANOW, &options);</DIV>
<DIV>write(fd,"devesh",6);</DIV>
<DIV>usleep(500000);<BR>/*<BR>fcntl(fd, F_SETFL, FNDELAY);</DIV>
<DIV>nread = read(fd,buffer,5);</DIV>
<DIV>//if (nread < 0)<BR>//write(2,"ERROR in read\n",20);</DIV>
<DIV>printf("\nnread = %d\n",nread);<BR>printf("tong = %s\n",buffer);</DIV>
<DIV> </DIV>
<DIV><BR>close(fd);<BR>*/</DIV>
<DIV> fcntl(fd, F_SETFL, FNDELAY); // don't block serial read</DIV>
<DIV> if (!readport(fd,sResult)) {<BR>  printf("read failed\n");<BR>  close(fd);<BR>  return 1;<BR> }<BR> printf("readport=%s\n", sResult);<BR> close(fd);<BR> return 0;</DIV>
<DIV>}<BR> </DIV><FONT color=#ff0000 size=6>
<P align=center>
<SPAN style="width:100%;height:2px;border-bottom:1px solid rgb(212,208,200); border-top:1px solid rgb(128,128,128);background-color:black;overflow:hidden; margin:8px 0px;"></SPAN>

<P></P>
<P align=left><FONT color=#000000 size=3>     <FONT size=4>   [DEV'H]</FONT></FONT></P>
<P align=left><FONT color=#000000 size=4>   Devesh Sharma</FONT></P>
<P align=left><FONT color=#000000 size=4>"Have A Nice Time"</FONT></P>
<P align=center><FONT size=4></FONT>
<SPAN style="width:100%;height:2px;border-bottom:1px solid rgb(212,208,200); border-top:1px solid rgb(128,128,128);background-color:black;overflow:hidden; margin:8px 0px;"></SPAN>

<P></P></FONT><FONT size=5></FONT>
<P align=left></P><FONT color=#ff0000 size=6>
<P align=center>
<SPAN style="width:100%;height:2px;border-bottom:1px solid rgb(212,208,200); border-top:1px solid rgb(128,128,128);background-color:black;overflow:hidden; margin:8px 0px;"></SPAN>

<P></P>
<P> </FONT></P>
<P> </P>
<DIV></DIV></div><br>


      <!--2--><hr size=1></hr> Unlimited freedom, unlimited storage. <a href="http://in.rd.yahoo.com/tagline_mail_2/*http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html/">Get it now</a></body></html>