delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1998/12/30/20:47:04

From: cgf AT cygnus DOT com (Christopher Faylor)
Subject: Re: Can outsiders get simple questions answered?
30 Dec 1998 20:47:04 -0800 :
Message-ID: <19981230131533.B12786.cygnus.gnu-win32@cygnus.com>
References: <367F31DC DOT B8E71A57 AT sdrc DOT com>
Mime-Version: 1.0
To: Dan Hensley <dan DOT hensley AT sdrc DOT com>
Cc: gnu-win32 AT cygnus DOT com

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 AT cygnus DOT com
http://www.cygnus.com/
-
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".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019