Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sources DOT redhat DOT com Delivered-To: mailing list cygwin AT sources DOT redhat DOT com Message-ID: <3AA5BFD1.43809E15@beamreachnetworks.com> Date: Tue, 06 Mar 2001 20:57:53 -0800 From: "Eric M. Monsler" X-Mailer: Mozilla 4.76 [en] (WinNT; U) X-Accept-Language: en MIME-Version: 1.0 To: "cygwin AT cygwin DOT com" Subject: Serial port interface under cygwin. Lossy? Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit All, I have a small application that communicates with embedded devices across the PC's serial port. I have a trivial header and trailer defining a message packet across the interface. I have been testing it by running my application on both ports, with a cable between them, and sending messages. When I run at 115200 baud, everything works great. When I run at 9600 baud, I lose a significant fraction of the messages. Like, half of them. Some lost because the header was not received properly, but more often because the 1-byte trailer was not the correct value (or, was not in the correct location). Has anyone seen this type of behavior with cygwin's serial port interface? I have no particular reason to blame cygwin vs. NT's serial drivers, or the PC's hardware, but I do see the same effect on two different PC's, different motherboards. So, I thought I'd ask. A snip of the code I use to setup the port is below. Eric Monsler /************* Port open and setup code ****************************/ /* Now we know we have the correct parameters to use, proceed to open port and write */ fd = open(serialdevice, O_RDWR | O_NOCTTY | O_NDELAY); if (fd <0) {perror(serialdevice); exit(-1); } #if DEBUG printf("Opening serial port %s returned: %d\n",serialdevice,fd); #endif tcgetattr(fd,&oldtio); /* save current port settings */ /* Start with old settings, then we'll modify */ newtio = oldtio; /* Now do the port setup to match what the EPLD is expecting */ /* Set baudrate */ cfsetispeed(&newtio,baud_enum); cfsetospeed(&newtio,baud_enum); /* Enable the receiver and set local. */ newtio.c_cflag |= (CLOCAL | CREAD); if(strcmp(parity,"8N1") == 0) { /* Set 8 bit characters, no parity, 1 stop (8N1) */ newtio.c_cflag &= ~PARENB; /* Clear previous parity bits values */ newtio.c_cflag &= ~CSTOPB; /* Clear previous stop bits values */ newtio.c_cflag &= ~CSIZE; /* Clear previous charsize bits values */ newtio.c_cflag |= CS8; /* Set for 8 bits. */ } else { printf("Unsupported parity selection, using 8N1.\n"); /* FIXME */ printf("Actually, only 8N1 supported at this time \n"); /* Set 8 bit characters, no parity, 1 stop (8N1) */ newtio.c_cflag &= ~PARENB; /* Clear previous parity bits values */ newtio.c_cflag &= ~CSTOPB; /* Clear previous stop bits values */ newtio.c_cflag &= ~CSIZE; /* Clear previous charsize bits values */ newtio.c_cflag |= CS8; /* Set for 8 bits. */ } /* I think we want to disable hardware flow control. FIXME */ newtio.c_cflag &= ~CRTSCTS; /* When we read, we want completely raw access */ newtio.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); /* I think we want to disable software flow control. FIXME */ newtio.c_iflag &= ~(IXON | IXOFF | IXANY); /* Set output filtering to raw. */ newtio.c_oflag &= ~OPOST; /* Set readsize and timeout to some reasonable values, just to be safe */ newtio.c_cc[VTIME] = 0; /* inter-character timer unused */ newtio.c_cc[VMIN] = 0; /* nonblocking read */ /* Now we can flush, and then make the control changes! */ tcflush(fd, TCIFLUSH); tcsetattr(fd,TCSANOW,&newtio); -- Want to unsubscribe from this list? Check out: http://cygwin.com/ml/#unsubscribe-simple