Hello,
i wrote a small program which sends one byte data over serial port 0 and receives one as answer.
As the conencted device reported serial overflow we connected another pc to the serial port. The Problem is:
The other PC gets the correct byte, but after one or two seconds it receives multiple other bytes.
The code i used for serial communication is (mostly taken out of the serial programming guide):
Thanks for your helpCode:int CheckAmp(int b) { struct termios newtio, oldtio; char *port="/dev/ttyS0"; int portfd; sigset_t block_mask; struct sigaction saio; portfd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NONBLOCK); if (portfd <0) { close(portfd); return 0; } fcntl(portfd, F_SETOWN, getpid()); fcntl(portfd, F_SETFL, FASYNC); sigemptyset (&block_mask); saio.sa_handler = signal_handler_IO; saio.sa_mask = block_mask; saio.sa_flags = 0; saio.sa_restorer = NULL; sigaction(SIGIO,&saio,NULL); newtio.c_cflag = B9600 | CRTSCTS | CS8 | CLOCAL | CREAD; newtio.c_iflag = IGNPAR; newtio.c_oflag = 0; newtio.c_lflag = 0; newtio.c_cc[VMIN]= 0; newtio.c_cc[VTIME]= 5; tcflush(portfd, TCIFLUSH); tcsetattr(portfd,TCSANOW,&newtio); write(portfd, &b, 1); char rd; int STOP=FALSE; char buff[255]; int res; wait_flag=TRUE; while (STOP==FALSE) { if (wait_flag==FALSE) { printf("Reading...\n"); res = read(portfd,buf,1); buf[res]=0; printf("Got %i \n", buf[0]); STOP=TRUE; } } rd = buf[0]; checkamp = rd; printf("CheckAmp: 0x%hx \n", rd); tcflush(portfd, TCIFLUSH); close(portfd); return 0; } void signal_handler_IO (int status) { printf("received SIGIO signal.\n"); wait_flag = FALSE; }



LinkBack URL
About LinkBacks


