From: Norton Allen <allen@huarp.harvard.edu>
To: "cygwin@cygwin.com" <cygwin@cygwin.com>
Subject: character device canonical mode
Date: Thu, 13 Jan 2022 12:37:56 -0500 [thread overview]
Message-ID: <5255058c-74e0-f351-3c91-e63a54a1e323@huarp.harvard.edu> (raw)
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;
}
next reply other threads:[~2022-01-13 17:37 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-13 17:37 Norton Allen [this message]
2022-01-14 9:34 ` Corinna Vinschen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5255058c-74e0-f351-3c91-e63a54a1e323@huarp.harvard.edu \
--to=allen@huarp.harvard.edu \
--cc=cygwin@cygwin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).