delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/02/24/15:46:37

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
X-Authentication-Warning: shadizar.dyndns.org: blackwolf set sender to mbarilli AT midsouth DOT rr DOT com using -f
To: cygwin AT cygwin DOT com
Subject: Can't set CREAD flag on serial port?
From: mbarilli AT midsouth DOT rr DOT com
Date: Tue, 24 Feb 2004 14:59:17 -0600
Message-ID: <873c908a8q.fsf@shadizar.dyndns.org>
User-Agent: Gnus/5.090024 (Oort Gnus v0.24) Emacs/21.3 (gnu/linux)
MIME-Version: 1.0
X-IsSubscribed: yes

I'm trying to write an application to access a serial port on a
Windows 2000 box, but the CREAD flag doesn't stay set when I do
`tcsetattr' and check the values with `tcgetattr'.  Trying to read
from the port returns a ``Resource temporarily unavailable'' error (as
generated from perror).  What would cause an app to fail to read from
the port, or is this a Win2K issue (permissions or something)?

One thing I should mention--this is a null modem cable attached to the
box.  Would that have a bearing on the issue?

The following is the relevant code:

int
main ( void ) {

    char buf[32];
    int n;
    struct termios newtio;
    struct termios oldtio;
    int tty_fd;

    tty_fd = open("/dev/com2",O_RDWR|O_NDELAY|O_BINARY);

    tcgetattr(tty_fd,&oldtio);

    memcpy( &newtio, &oldtio, sizeof(newtio) );

    newtio.c_cflag &= ~(CSIZE|CBAUD|CRTSCTS|PARENB|CSTOPB);
    newtio.c_cflag |= (CLOCAL|CREAD|CS8);
    cfsetispeed(&newtio,tty_speed);
    cfsetospeed(&newtio,tty_speed);

    newtio.c_lflag &= ~(ICANON|ECHO|ECHOE|ISIG);
    newtio.c_lflag |= IEXTEN;

    newtio.c_iflag &= ~(INPCK|ISTRIP|IXON|IXOFF|IXANY|BRKINT|ICRNL|INLCR|IGNCR|IUCLC);

    newtio.c_oflag &= ~OPOST;

    newtio.c_cc[VMIN] = 0;
    newtio.c_cc[VTIME] = 0;

    printf("+++ setting termios: cflag=%08X lflag=%08X iflag=%08X oflag=%08X ispeed=%d/%08X ospeed=%d/%08X\n",
           newtio.c_cflag,
           newtio.c_lflag,
           newtio.c_iflag,
           newtio.c_oflag,
           newtio.c_ispeed,
           newtio.c_ispeed,
           newtio.c_ospeed,
           newtio.c_ospeed);
 
    tcsetattr(tty_fd,TCSANOW,&newtio);

    /* *** At this point the CREAD flag is no longer set */
    tcgetattr(tty_fd,&newtio);
    printf("+++ updated termios: cflag=%08X lflag=%08X iflag=%08X oflag=%08X ispeed=%d/%08X ospeed=%d/%08X\n",
           newtio.c_cflag,
           newtio.c_lflag,
           newtio.c_iflag,
           newtio.c_oflag,
           newtio.c_ispeed,
           newtio.c_ispeed,
           newtio.c_ospeed,
           newtio.c_ospeed);

    while ( 1 ) {
        /* *** `read' fails at this point */
        n = read( tty_fd, buf, sizeof(buf) );
        if ( n < 0 ) {
            perror("read");
            exit(2);
            }
        if ( n == 0 )
            break;
        write(1,buf,n);
        }

    tcsetattr(tty_fd,TCSANOW,&oldtio);

    close(tty_fd);

    return 0;

    }

-- 
Michael J. Barillier               | ``Those who make peaceful
email: mbarilli(at)midsouth.rr.com | revolution impossible will make
web: <http://shadizar.dyndns.org/> | violent revolution inevitable.''
Public key available on request.   |     -- John F. Kennedy

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


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