This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Problem with Linux serial port


I have a small program running data transfer on serial port.
Ironically, the serial port data transfer works smoothly on Cygwin
window much better than the linux. On linux, the transfer data on
serial port can be freezed intermittently, which does not happen on
Cygwin window. Has anyone know why and how to fix it?

I am using an open source serial port program from  Brian J. Hennings,
using native read, write and select. I suspect that the problem is
likely introduced by following port configuration:

int OpenPort (char *port)
      int err;
    struct termios options, old_options;

    //Setup Serial

    fprintf(stderr,"Open Comms on port %s\n", port);

    if ( (Serial = open ( port , O_RDWR | O_NONBLOCK | O_SYNC ) ) == -1)
        fprintf(stderr, "Cannot Open Comms - %s  errno = %d\n", port, errno);
        return -errno;
    memset (&options, 0,sizeof(options));
    options.c_cflag  &= ~PARENB;           // no parity
    options.c_cflag  &= ~CSTOPB;           // one stopbit
    options.c_cflag  &= ~CRTSCTS;          // No hardware flow control.
    options.c_cflag  &= IXON;
    options.c_cflag  &= IXOFF;
    options.c_cflag  &= CSIZE;
    options.c_cflag |= CS8;                // 8N1
    options.c_cflag |= (CLOCAL | CREAD);   // enable Localmode, receiver
    options.c_cc[VMIN] = 0;                // set min read characters if 0
                                          //   VTIME takes over
    options.c_cc[VTIME] = V_TIME;          // wait V_TIME ms for character

    err = cfsetospeed(&options, B115200);
    if (err < 0) {
        printf ("Could not set output speed! Error = %d\n", err);
        close (Serial);
        return -1;
    } /*End of if*/

    err = cfsetispeed(&options, B115200);
    if (err < 0) {
        printf ("Could not set input speed! Error = %d\n", err);
        close (Serial);
        return -1;
    } /*End of if*/

    if (tcsetattr(Serial,TCSANOW, &options) < 0) {
        printf ("Failed to set Serial port options!\n");
        close (Serial);
        return -1;
    } /*End of if*/

    tcflush (Serial, TCIOFLUSH);

    fprintf(stderr, "Port %s OPENED \n", port);

    return 0;
 } /*End of OpenPort ()*/

Thank you.

Kind Regards,


Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]