« Return to Thread: Looking for basic documentation on Cygwin and Serial Ports

RE: Looking for basic documentation on Cygwin and Serial Ports

by Nefastor :: Rate this Message:

Reply to Author | View in Thread

Nefastor wrote:
Thanks for all the info, everyone . 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.

- So I tested tcsetattr() by omitting the CRTSCTS flag in my parameters. With it, the program would not send data until the terminal was ready to receive, without it, the program would send the data no matter what. So tcsetattr() appears to work.

My terminal is an ultra-reliable PSION Series 3A I've been using for almost a decade. I've tested it again with Windows' Hyperterminal and COM3 to verify that it wasn't a hardware problem.

My conclusion would be that either the FTDI drivers are broken or Cygwin has trouble interfacing with them. Dave, since you're an FTDI user too, does any of this sound familiar ?

Here's the program I've written :

#include <stdlib.h>
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>

int main (int argc, char* argv[])
{
  struct termios params;  
  int tty;              

  tty = open ("/dev/ttyS2", O_RDWR | O_NOCTTY | O_NONBLOCK);
 
  if (tty < 0)
   {
      printf ("Unable to open /dev/ttyS2\n");
      exit (1);
   }
   
  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);
   
  write (tty,"Hello World",11);
 
  close (tty);

  return 0;
}

 « Return to Thread: Looking for basic documentation on Cygwin and Serial Ports