From: dan DOT hensley AT sdrc DOT com (Dan Hensley) Subject: Re: Can outsiders get simple questions answered? 28 Dec 1998 20:13:07 -0800 Message-ID: <3687C4AE.9C66D325.cygnus.gnu-win32@sdrc.com> References: <367F31DC DOT B8E71A57 AT sdrc DOT com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: "Christopher G. Faylor" Cc: gnu-win32 AT cygnus DOT com Chris, > >trying to get this functionality to work. I discovered that in notty mode, > >select() works differently from tty mode (extra required), so I need to run in > >tty mode. > Despite all this, I don't understand what you are referring to regarding the > "extra required". There shouldn't be any difference between a Cygwin tty > and the console as far as select is concerned. I was mistaken on the behavior of select() here. Indeed, an extra is required, but it's due to different behavior in the read() command I use after select() to get the data from the buffer. Select appears to work the same no matter what tty mode is selected. I've attached my sample source code below. > Could you provide more detail, please? What version of cygwin are you running > and where are you running it? cygcheck output would show this. And, if you have a simple test case > which illustrates this problem, that would also be helpful. I'm running b20.1 (I downloaded b20 and replaced cygwin1.dll). I'm running NT4.0 w/ sp4 on a PII. MAKE_MODE=UNIX, and CYGWIN either =tty or nothing. I'm running from within the default bash shell. I've also installed the FORTRAN overlay; other than that, I haven't done any customization. Incidentally, this source code does not read from the serial device. I cannot get it (select) to recognize input from my barcode reader. I have verified that the barcode device is on the correct serial port and is working correctly (via HyperTerminal). You can see that the serial device is not being opened correctly by looking at the output of tcgetattr() and tcsetattr()--setting the device attributes does not change them to the correct values. By the way, I compile this code using gcc with no arguments. ------------------------------------------------------------------------ #include #include #include #include #include #include #include #define BUFFERSIZ 30 void main( void ) { int i, j, idBarc, iStat, iSet, iRet ; fd_set rfds ; struct timeval tv ; struct termios termios ; char pcDevNm[]="com1", pcBuf[101], cBuf[BUFFERSIZ]="Enter something: " ; /* * Open the serial port for the barcode reader device */ if ( (idBarc = open( pcDevNm, O_RDWR )) == -1 ) { printf( "Cannot open device %s\n", pcDevNm ) ; exit( 0 ) ; } else { printf( "Opened barcode device %s\n", pcDevNm ) ; } /* * Get the serial port attributes */ if( (iStat = tcgetattr( idBarc, &termios ) ) == -1 ) { printf( "Cannot get port attributes...\n" ) ; exit( 0 ) ; } else { printf( "Got serial port attributes\n" ) ; printf( "===== Here's the original setup =====\n" ) ; printf( " termios_iflag=%o\n", termios.c_iflag ) ; printf( " termios_oflag=%o\n", termios.c_oflag ) ; printf( " termios_cflag=%o\n", termios.c_cflag ) ; printf( " termios_lflag=%o\n", termios.c_lflag ) ; printf( "=====================================\n" ) ; } /* * Set the serial port attributes */ termios.c_iflag = IGNBRK | ICRNL ; /* ICRNL ; */ /* termios.c_oflag = (tcflag_t) (NULL) ; */ termios.c_cflag = CREAD | CS7 | PARENB | B9600 ; termios.c_lflag = ICANON ; printf( "===== Here's what I want to set =====\n" ) ; printf( " termios_iflag=%o\n", termios.c_iflag ) ; printf( " termios_oflag=%o\n", termios.c_oflag ) ; printf( " termios_cflag=%o\n", termios.c_cflag ) ; printf( " termios_lflag=%o\n", termios.c_lflag ) ; printf( "=====================================\n" ) ; if( (iStat = tcsetattr( idBarc, TCSANOW, &termios ) ) == -1 ) { printf( "Cannot set port attributes...\n" ) ; exit( 0 ) ; } else { printf( "Set serial port attributes\n" ) ; } /* * Flush the buffer */ if( (iStat = tcflush( idBarc, TCIOFLUSH ) ) == -1 ) { printf( "Cannot flush the buffer...\n" ) ; exit( 0 ) ; } /* * Get the serial port attributes */ if( (iStat = tcgetattr( idBarc, &termios ) ) == -1 ) { printf( "Cannot get port attributes...\n" ) ; exit( 0 ) ; } else { printf( "Got serial port attributes\n" ) ; printf( "==== Here's what actually got set ===\n" ) ; printf( " termios_iflag=%o\n", termios.c_iflag ) ; printf( " termios_oflag=%o\n", termios.c_oflag ) ; printf( " termios_cflag=%o\n", termios.c_cflag ) ; printf( " termios_lflag=%o\n", termios.c_lflag ) ; printf( "=====================================\n" ) ; } /* * Initialize a few things */ FD_ZERO( &rfds ) ; FD_SET( 0, &rfds ) ; FD_SET( idBarc, &rfds ) ; /* * Enter something */ iRet = write( 1, cBuf, 20 ) ; iRet = select( idBarc+1, &rfds, NULL, NULL, NULL ) ; printf( "Select finished, iRet=%d\n", iRet ) ; /* * Find out where input came from */ if( iRet != -1 ) { iSet = -1 ; printf( "Data is available now " ) ; if( FD_ISSET( 0, &rfds ) ) { printf( "from the keyboard\n" ) ; iSet = 0 ; } if( FD_ISSET( idBarc, &rfds ) ) { printf( "from the scanner\n" ) ; iSet = idBarc ; } printf( "\n" ) ; /* * Get the data */ printf( "Getting the data from the buffer\n" ) ; if( iSet != -1 ) { iStat = read( iSet, (void *) pcBuf, 100 ) ; if( iStat > 0 ) { pcBuf[ iStat ] = (char) NULL ; printf( "iStat=%d\nRead: '%s'\n", iStat, pcBuf ) ; } else printf( "No data read\n" ) ; } } else printf( "No data at all\n" ) ; /* * Close the COM port */ close( idBarc ) ; exit( 0 ) ; } ------------------------------------------------------------------------ Thanks, Dan - For help on using this list (especially unsubscribing), send a message to "gnu-win32-request AT cygnus DOT com" with one line of text: "help".