Looking for basic documentation on Cygwin and Serial Ports

Gary Johnson garyjohn@spk.agilent.com
Fri May 2 00:54:00 GMT 2008


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/



More information about the Cygwin mailing list