This is the mail archive of the cygwin 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]
Other format: [Raw text]

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


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;


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


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

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

       if ( select(max_fd + 1,
                   NULL) < 0)

       if (FD_ISSET(socket_fd, &read_set)
        && !FD_ISSET(serial_fd, &read_set)
        && FD_ISSET(serial_fd, &write_set)) {
           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);
               } else
                   error("write", 1);

       if (FD_ISSET(serial_fd, &read_set)
        && FD_ISSET(socket_fd, &write_set)) {
           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);
                   } else
                       error("write", 1);




---------------- /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 <>:
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:
Problem reports:

-- Unsubscribe info: Problem reports: Documentation: FAQ:

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