This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Can outsiders get simple questions answered?


Chris,
    Yep, you were right.  :-)  I thought I'd copied everything over, but I forgot that library.  It looks like
it's working better now--select() recognizes when data is entered through the serial port, which it wasn't doing
before.  But it still looks like tcsetattr isn't able to set all of my attributes correctly, namely:

iflag:  ICRNL
cflag:  CREAD

    I'm also finding some other strange behavior:
* When I set both serial port and keyboard for polling by select, and I enter something via serial port, it
FD_ISSET() correctly tells me that the serial port had the input.  However, read() locks up my bash session (or
at least won't return control--I can still type) when I try to read the buffer after serial port input.  I
believe this may be due to ICRNL not being set.  Any thoughts?
* When I set both serial port and keyboard for polling by select, and I enter something via the keyboard,
FD_ISSET() tells me that both the keyboard and the serial port had input.
* When I set only the keyboard for polling by select, everything works great.

    Believe it or not, I actually got slightly further when I had replaced termios.h and cygwin1.dll but not
libcygwin1.a.  Then, I was able to read the buffer, but it was all garbled (as expected) since the port
attributes were set to 8N1 and my scanner is set to 7E1.  But read() was working fine.  Strange...

It looks like this snapshot is on the right track though!

Thanks,
Dan

Christopher Faylor wrote:

> >From this, it looks like you haven't replaced your libcygwin.a.
>
> You'll need to recompile your program using the new termios.h,
> link it using the new libcygwin.a, and use the new cygwin1.dll.
>
> -chris
>
> On Wed, Dec 30, 1998 at 12:53:10PM -0700, Dan Hensley wrote:
> >    Well, it certainly works differently from before.   Here's the new output from my program:
> >Trying to open barcode device /dev/co
> >Opened barcode device /dev/com1
> >Got serial port attributes
> >===== Here's the original setup =====
> >  termios_iflag=4
> >  termios_oflag=4075
> >  termios_cflag=0
> >  termios_lflag=0
> >=====================================
> >===== Here's what I want to set =====
> >  termios_iflag=401
> >  termios_oflag=4075
> >  termios_cflag=655
> >  termios_lflag=2
> >=====================================
> >Set serial port attributes
> >Got serial port attributes
> >==== Here's what actually got set ===
> >  termios_iflag=4
> >  termios_oflag=4075
> >  termios_cflag=0
> >  termios_lflag=0
> >=====================================
> >
> >So the attributes aren't quite being set correctly (actually, it looks like fewer attributes are being set
> >than before), but they're being set differently from before.  I need to take a closer look at my program,
> >since at first glance it looks like select is returning something different from before.  I'll let you know
> >when I find out more...
> >
> >Thanks,
> >Dan
> >
> >Christopher Faylor wrote:
> >
> >> You might want to try out the latest snapshot at:
> >>
> >> ftp://ftp.cygnus.com/pub/noer/winsup-snapshot/
> >>
> >> There has been some additional work done on serial stuff.
> >>
> >> For this to be effective, you'll need to replace your copy of libcygwin.a
> >> with the version found in this directory and your version of sys/termios.h
> >> with the version found here.
> >>
> >> -chris
> >>
> >> On Mon, Dec 28, 1998 at 10:49:34AM -0700, Dan Hensley wrote:
> >> >Chris,
> >> >
> >> >> >trying to get this functionality to work.  I discovered that in notty mode,
> >> >> >select() works differently from tty mode (extra <CR> required), so I need to run in
> >> >> >tty mode.
> >> >
> >> >> Despite all this, I don't understand what you are referring to regarding the
> >> >> "extra <CR> 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 <CR> 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 <stdlib.h>
> >> >#include <stdio.h>
> >> >
> >> >#include <sys/time.h>
> >> >#include <sys/types.h>
> >> >#include <fcntl.h>
> >> >#include <termios.h>
> >> >#include <unistd.h>
> >> >
> >> >#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
> >> >
> >> >
> >> >
> >> >
> >>
> >> --
> >> cgf@cygnus.com
> >> http://www.cygnus.com/
> >
> >--
> >Dan Hensley
> >Engineer - SDRC Operations (ATA)
> >Denver, CO        W:303/464-7049
> >http://www.sdrc.com/
> >
> >
>
> --
> cgf@cygnus.com
> http://www.cygnus.com/

--
Dan Hensley
Engineer - SDRC Operations (ATA)
Denver, CO        W:303/464-7049
http://www.sdrc.com/


-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]