Apparently Cygwin does not support canonical mode on serial devices. On input canonical mode will wait for a newline before returning from a read(). The bit is cleared/ignored by tcsetattr() as demonstrated by a subsequent tcgetattr() in the test program below.

I am wondering if this is because of a fundamental difference between the Windows serial device model and POSIX or just because the appropriate mappings haven't been implemented. (I have studiously avoided Windows programming for decades, and Cygwin has been my enabler!)

My test program:

#include <termios.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>

void check_rv(int rv, const char *where) {
  if (rv) {
    printf("Error %s: %d %s\n", where, errno, strerror(errno));
    exit(1);
  }
}

int main(int argc, char **argv) {
  termios termios_p;
  if (argc != 2) {
    printf("Must specify a serial device\n");
    exit(1);
  }
  int fd = open(argv[1], O_RDWR | O_NONBLOCK);
  check_rv(fd == -1, "opening serial device");
  check_rv(tcgetattr(fd, &termios_p), "from tcgetattr()");
  printf("c_lflag = 0x%X after open\n", termios_p.c_lflag);
  termios_p.c_lflag |= ICANON;
  printf("c_lflag = 0x%X to pass to tcsetattr()\n", termios_p.c_lflag);
  check_rv(tcsetattr(fd, TCSANOW, &termios_p), "from tcsetattr()");
  check_rv(tcgetattr(fd, &termios_p), "from 2nd tcgetattr()");
  printf("c_lflag = 0x%X after tcsetattr()\n", termios_p.c_lflag);
  return 0;
}


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

Reply via email to