hai all, Here i want to communicate with two serial ports interactivelly.(i.e)If i send a byte to com1 i have to receive in com2 correpondingly.Here I am getting the subsequent bytes but in between i am getting some junk charecters too.(For that i have connected a null modem cable in between com1 and com2.)
For clear Understanding i am giving my transmitting and receving code.
// Transmitting code
#include /* Standard input/output definitions */ #include /* String function definitions */ #include /* UNIX standard function definitions */ #include /* File control definitions */ #include /* Error number definitions */ #include /* POSIX terminal control definitions */
int main() { int fd,c,i; struct termios options; char c, buff[10]; fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY ); if (fd == -1) perror("Unable to open /dev/ttyS0\n"); else { fprintf(stdout,"enter any byte"); fgets(buff,sizeof(buff),stdin); fcntl(fd, F_SETFL, 0); tcgetattr(fd, &options); cfsetispeed(&options,B115200); cfsetospeed(&options,B115200); options.c_cflag |= (CLOCAL | CREAD); options.c_cflag &= ~PARENB; options.c_cflag &= ~CSTOPB; options.c_cflag &= ~CSIZE; options.c_cflag |= CS8; options.c_cflag |=(ICANON | ECHO | ECHOE); options.c_oflag |=OPOST; tcsetattr(fd, TCSANOW, &options); while((c=fgetc(stdin)!=EOF) { buff[i]=c; if(write(fd,buff,1)]c here i want to clear the buffer after receiving 1st byte.so that i can put that function in loop.Is there any function to do that? Hope i explaned clearly.If you have any guide other than posix standard,please give me the url. Thanks in advance.
With Regards
emb in linux.