From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4993 invoked by alias); 13 May 2014 13:31:44 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 4976 invoked by uid 89); 13 May 2014 13:31:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.9 required=5.0 tests=AWL,BAYES_40,RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mail.ubitronix.com Received: from mail.ubitronix.com (HELO mail.ubitronix.com) (83.164.197.107) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 13 May 2014 13:31:33 +0000 Received: from ex01-ubitronix.ubitronix.local ([10.1.10.11]) by ex01-ubitronix.ubitronix.local ([10.1.10.11]) with mapi; Tue, 13 May 2014 15:31:29 +0200 From: Manuel Wienand To: "cygwin@cygwin.com" Date: Tue, 13 May 2014 14:19:00 -0000 Subject: Can't read from serial port without writing to it before Message-ID: <0C11C5BF0B29FD43A8D0250F711D497FB4844C32B3@ex01-ubitronix.ubitronix.local> Content-Type: text/plain; charset="iso-2022-jp" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-IsSubscribed: yes X-SW-Source: 2014-05/txt/msg00261.txt.bz2 Hello! I have got the problem, that I can=1B$B!F=1B(Bt read from a serial port wit= hout writing at least one byte to it before. Another workaround is to use an terminal application (I tried with HTerm) a= nd connect (and then disconnect again) to the COM port, this seems to fix i= t for the next run. Closing the COM port properly before exiting the program doesn=1B$B!G=1B(Bt= seem to have any effect on the faulty behaviour. Test case: PC: Win7 (x64), Cygwin 1.7.29 (x32) Using a serial cable to connect to a development board which is just spammi= ng data over the serial. =1B$B"M=1B(B PC reads only, board writes only. The code of the PC program is attached at the end of this mail. I hope you are able to reproduce and fix this problem. Thanks in advance. Manuel #include #include #include #include #include #include #include #include #include #include #include #include int kbport =3D -1; int posix_com_close(int port) { int rtnval =3D 0; if (port !=3D -1) { rtnval =3D (int) close(port); } return(rtnval); } int posix_com_open(char *devicename) { int rtnval =3D 0; struct termios t; int local_databits =3D CS8; // 8 Databits. int local_stopbits =3D 0; // 1 Stopbit int local_parity =3D 0; // No parity int local_rate =3D B9600; // 9600 Baud /* Open the com port for read/write access */ rtnval =3D open(devicename,O_RDWR); t.c_iflag =3D IGNPAR; t.c_oflag =3D 0; t.c_cflag &=3D ~CSIZE; /* Zero out the CSIZE bits */ t.c_cflag =3D CLOCAL | local_databits | local_stopbits | local_parity; t.c_lflag =3D IEXTEN; if ((cfsetispeed(&t,local_rate) !=3D -1) && (cfsetospeed(&t,local_rate) != =3D -1)) { if (tcsetattr(rtnval,TCSANOW,&t) =3D=3D -1) rtnval =3D -1; } else rtnval =3D -1; return(rtnval); } char posix_com_read(int port, char *dst) { if (port !=3D -1) return(read(port,dst,1) =3D=3D 1); else return(0); } char posix_com_write(int port, char src) { if (port !=3D -1) return(write(port,&src,1) =3D=3D 1); else return(0); } int main(void) { int myport =3D 0; char inchar =3D 0; int i=3D0; myport =3D posix_com_open("/dev/ttyS0"); puts("Starting to receive...");fflush(stdout); char test =3D 'A'; //posix_com_write(myport, test); // When using this line, reading will al= ways work. if (myport !=3D -1) { while (i<20) //while (1) // Since closing the COM port doesn't help, we can use this= instead. { i++; if (posix_com_read(myport,&inchar)) { if (isprint(inchar)) printf("%c",inchar); else printf("<%03d>",inchar); fflush(stdout); } } posix_com_close(myport); // Doesn't help. return EXIT_SUCCESS; } return EXIT_SUCCESS; } -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple