Mail Archives: cygwin/2008/05/01/20:54:54
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,¶ms); // 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,¶ms);
would become this:
tcgetattr (tty,¶ms); // 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(¶ms, B19200);
cfsetospeed(¶ms, B19200);
tcflush (tty, TCIFLUSH);
tcsetattr (tty,TCSANOW,¶ms);
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 -