public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Problem with Linux serial port
@ 2008-05-01 23:39 hce
  0 siblings, 0 replies; only message in thread
From: hce @ 2008-05-01 23:39 UTC (permalink / raw)
  To: cygwin

Hi,

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;
    }
    tcgetattr(Serial,&options);
    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,

Jim

--
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/

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-05-01 23:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-01 23:39 Problem with Linux serial port hce

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).