cygwin 1.5.23-2 : CREAD termios option don't work

Florent Morin morinflorent@gmail.com
Wed Jan 17 14:37:00 GMT 2007


Hello,

Like you say, CREAD isn't the real problem.

I use select() to read/write socket and read/write serial. But, after
writing the content of socket on serial port, I can't read serial port
(access denied).

This is an extract of my source code :

---------------- CODE ---------------------

    int serial_fd;
    int max_fd;

    unsigned char buffer[MAX_CANON];
    int size;
    int converted_size;

    unsigned char buffer2[MAX_CANON];
    int size2;

    fd_set read_set;
    fd_set write_set;

    nice(15);

    /* opening serial port read/write, non-block */
    serial_fd = open ( port_settings->device,
                       O_NONBLOCK | O_RDWR | O_NOCTTY);

    max_fd = socket_fd < serial_fd ? serial_fd : socket_fd;

    alarm(ALARM_TIMEOUT);

    while (1) {
        FD_ZERO(&read_set);
        FD_SET(socket_fd, &read_set);
        FD_SET(serial_fd, &read_set);

        FD_ZERO(&write_set);
        FD_SET(socket_fd, &write_set);
        FD_SET(serial_fd, &write_set);

        if ( select(max_fd + 1,
                    &read_set,
                    &write_set,
                    NULL,
                    NULL) < 0)
            perror("select");

        if (FD_ISSET(socket_fd, &read_set)
         && !FD_ISSET(serial_fd, &read_set)
         && FD_ISSET(serial_fd, &write_set)) {
            alarm(0);
            memset(&buffer, 0, MAX_CANON);
            size = read(socket_fd, buffer, MAX_CANON - 1);
            converted_size = convert_telnet(&buffer, size);
            while (write(serial_fd, buffer, converted_size) < 0) {
                if (errno == EAGAIN) {
                    error("write", 0);
                    sleep(1);
                } else
                    error("write", 1);
            }
            alarm(ALARM_TIMEOUT);
        }

        if (FD_ISSET(serial_fd, &read_set)
         && FD_ISSET(socket_fd, &write_set)) {
            alarm(0);
            memset(&buffer2, 0, MAX_CANON);
            printf("read serial");
            size2 = read(serial_fd, buffer2, MAX_CANON - 1);
            if (size2 > 0) {
                while (write(socket_fd, buffer2, size2) < 0) {
                    if (errno == EAGAIN) {
                        error("write", 0);
                        sleep(1);
                    } else
                        error("write", 1);
                }
            }
            alarm(ALARM_TIMEOUT);
        }

        sleep(1);

    }

    close(serial_fd);

---------------- /CODE ---------------------

I have tested it on Linux. It works fine. When I send data throw
telnet protocol, the data are received by the peripheral connected to
serial and vice-versa.

Perhaps I don't use the functions very well. So, if you can help me, thanks.

Florent Morin.


2007/1/12, Brian Ford <Brian.Ford@flightsafety.com>:
> On Fri, 12 Jan 2007, Corinna Vinschen wrote:
> > On Jan 11 16:53, Florent Morin wrote:
> > > For testing, I have tried with a working program : stty. It works fine
> > > with all options, but not with CREAD.
> > >
> > > $ stty cread < /dev/ttyS0
> > > stty: /dev/ttyS0: unable to perform all requested operations
> > >
> > > Can someone explain this ?
> >
> > Please consider to debug this yourself.  Cygwin has no volunteer which
> > is fluent with serial I/O right now.
>
> This is not a regression from 1.5.18, which I know worked fine with serial
> I/O.  I will try to test 1.5.23 when I get a chance, but I have no reason
> to suspect it is broken.
>
> CREAD appears to always be enabled but not indicated by tcgetattr or
> controllable via tcsetattr right now.  So, the test case above is not
> indicative of the original problem.
>
> To the OP, posting your code might be informative.
>
> --
> Brian Ford
> Lead Realtime Software Engineer
> VITAL - Visual Simulation Systems
> FlightSafety International
> the best safety device in any aircraft is a well-trained crew...
>
>
>
> --
> 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/
>
>

--
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/



More information about the Cygwin mailing list