Mail Archives: cygwin/2001/07/04/13:26:48
------_=_NextPart_000_01C104AD.ADA0D8DC
Content-Type: text/plain;
charset="iso-8859-1"
This seems to be similar to the problem Christopher Faylor and Dan Morris
were discussing in:
http://sources.redhat.com/ml/cygwin-developers/2000-12/msg00064.html
I have upgraded to the latest 1.3.2 DLL, but the problem (if it is the same)
persists.
This is my first submission, so I hope I provide enough information. I am
enclosing a .C file which should show the problem. The program is a simple
infinite loop. The system is configured to be non-blocking, and does
constant polling of the serial port. However, once the first character is
received, the system blocks on the next read. The code is not dead, because
if more characters are sent, the system receives them.
I have tried to use ioctl(..., FIONREAD, ...), to check if there are
character to read before trying, but Cygwin does not support this.
Regards, and thanks,
Anthony
Encl.
<<serial.c>>
------_=_NextPart_000_01C104AD.ADA0D8DC
Content-Type: application/octet-stream;
name="serial.c"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="serial.c"
#include <fcntl.h> /* File control definitions */=0A=
#include <sys/file.h>=0A=
#include <termios.h> /* POSIX terminal control definitions =
*/=0A=
=0A=
=0A=
int main(void)=0A=
{=0A=
int ch; /* Character received from keyboard */=0A=
int fd; /* Serial port file descriptor */=0A=
struct termios options;=0A=
unsigned char TmpChar[80];=0A=
=0A=
=0A=
fd =3D open_port("/dev/com1"); /* Open the serial port in no =
delay mode */=0A=
if (fd =3D=3D -1) { /* Could not open the port */=0A=
exit(1);=0A=
}=0A=
else {=0A=
tcgetattr(fd, &options); /* Get current options to modify them =
*/=0A=
options.c_lflag &=3D ~(ICANON | ECHO | ECHOE | ISIG | IEXTEN);=0A=
options.c_cflag |=3D (CLOCAL | CREAD); /* Enable RAW I/O and =
receiver & local mode */=0A=
cfsetispeed(&options, B115200); /* 115200bps input */=0A=
cfsetospeed(&options, B115200); /* 115200bps output */=0A=
options.c_cflag &=3D ~PARENB; /* No parity */=0A=
options.c_cflag &=3D ~CSTOPB; /* 1 Stop bit */=0A=
options.c_cflag &=3D ~CSIZE; /* Mask out data size */=0A=
options.c_cflag |=3D CS8; /* 8 bit data */=0A=
options.c_iflag &=3D ~(INLCR | ICRNL | IGNCR); /* Do not interpret =
S/W flow control either */=0A=
options.c_iflag &=3D ~(IXON | IXOFF | IXANY);=0A=
options.c_iflag |=3D IGNBRK;=0A=
tcsetattr(fd, TCSANOW, &options); /* Post the updated options =
*/=0A=
}=0A=
=0A=
for (;;) {=0A=
printf("Checking for serial input\n");=0A=
ch =3D read(fd, &TmpChar[0], 1);=0A=
if (ch > 0) {=0A=
printf("Got a character\n");=0A=
if (ch =3D=3D 'q') {=0A=
break;=0A=
}=0A=
}=0A=
else {=0A=
printf("No character waiting\n");=0A=
}=0A=
}=0A=
=0A=
close(fd); /* Close the serial port */=0A=
=0A=
return(0);=0A=
}=0A=
=0A=
=0A=
int open_port(const char *Port)=0A=
{=0A=
=0A=
int fd; /* File descriptor for the port */=0A=
=0A=
=0A=
fd =3D open(Port, O_RDWR | O_NOCTTY | O_NDELAY);=0A=
if (fd !=3D -1) { /* Successfully opened port */=0A=
fcntl(fd, F_SETFL, FNDELAY); /* Set to no delay mode */=0A=
}=0A=
=0A=
return(fd);=0A=
}=0A=
=0A=
/* EOF */=0A=
------_=_NextPart_000_01C104AD.ADA0D8DC
Content-Type: text/plain; charset=us-ascii
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
------_=_NextPart_000_01C104AD.ADA0D8DC--
- Raw text -