delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2022/01/13/12:38:36

X-Recipient: archive-cygwin AT delorie DOT com
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 14FE6385840D
Authentication-Results: sourceware.org; dmarc=none (p=none dis=none)
header.from=huarp.harvard.edu
Authentication-Results: sourceware.org;
spf=pass smtp.mailfrom=huarp.harvard.edu
Message-ID: <5255058c-74e0-f351-3c91-e63a54a1e323@huarp.harvard.edu>
Date: Thu, 13 Jan 2022 12:37:56 -0500
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.1
From: Norton Allen <allen AT huarp DOT harvard DOT edu>
To: "cygwin AT cygwin DOT com" <cygwin AT cygwin DOT com>
Subject: character device canonical mode
X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS,
SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4
X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on
server2.sourceware.org
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.29
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com>
X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 20DHcZJ1011418

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

- Raw text -


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