delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2008/05/01/20:54:54

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Date: Thu, 1 May 2008 17:53:54 -0700
From: Gary Johnson <garyjohn AT spk DOT agilent DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: Looking for basic documentation on Cygwin and Serial Ports
Message-ID: <20080502005354.GB4342@suncomp1.spk.agilent.com>
Mail-Followup-To: cygwin AT cygwin DOT com
References: <16827997 DOT post AT talk DOT nabble DOT com> <480F02EA DOT AF265921 AT dessent DOT net> <16853883 DOT post AT talk DOT nabble DOT com> <28D25EB5A34E89408B73B6793C742171CAB6B4 AT nutmeg DOT CAM DOT ARTIMI DOT COM> <16897467 DOT post AT talk DOT nabble DOT com> <16995311 DOT post AT talk DOT nabble DOT com>
MIME-Version: 1.0
In-Reply-To: <16995311.post@talk.nabble.com>
X-Operating-System: SunOS suncomp1 5.8 sparc
User-Agent: Mutt/1.5.17 (2007-11-01)
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On 2008-05-01, Nefastor wrote:
> Nefastor wrote:
> > 
> > Thanks for all the info, everyone :-D. I'm gonna try a few things and get
> > back to you.
> > 
> 
> So I've tried a few things, and obviously all hell broke loose, sort of.
> I've written a very simple "Hello World" program, which I'll paste at the
> end of this message. The program is based 90% on code copy-pasted directed
> from the serial programming HOWTO. Here's what it does :
> 
> - Open COM3
> - Get its attribute
> - Modify them to my desired baudrate and such
> - Send out the string "Hello World"
> - Close COM3
> 
> Opening and closing COM3 works. The rest exhibits faulty but consistent
> behavior :
> 
> - The baudrate never changes and I can't seem to figure out what it is, but
> the terminal I plugged on COM3 always gets the same garbled characters
> instead of "Hello World". Also, the terminal flags me a buffer overrun. This
> suggested that tcsetattr() didn't work.

I ported a program using a serial port from HP-UX to Cygwin a while 
ago and ran into similar problems:  everything seemed to work OK 
except for the speed settings.  I don't remember the issues exactly, 
but I finally got it to work by setting the speeds using 
cfsetispeed() and cfsetospeed() instead of setting the speed bits of 
c_cflag directly.

Applying this to your program,

>   tcgetattr (tty,&params);    // get the current port settings
>   params.c_cflag = B19200 | CRTSCTS | CS8 | CLOCAL | CREAD;
>   params.c_iflag = IGNPAR;
>   params.c_oflag = 0;
>   params.c_lflag = ICANON; 
>   tcflush (tty, TCIFLUSH);
>   tcsetattr (tty,TCSANOW,&params);

would become this:

    tcgetattr (tty,&params);    // get the current port settings
    params.c_cflag = CRTSCTS | CS8 | CLOCAL | CREAD;
    params.c_iflag = IGNPAR;
    params.c_oflag = 0;
    params.c_lflag = ICANON;
    cfsetispeed(&params, B19200);
    cfsetospeed(&params, B19200);
    tcflush (tty, TCIFLUSH);
    tcsetattr (tty,TCSANOW,&params);

HTH,
Gary


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

- Raw text -


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