delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/05/16/05:19:21

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Subject: Serial programming - Writing bytes in a blocking mode - Problem with tcdrain() ?
To: cygwin AT cygwin DOT com
Message-ID: <OFAFBFF454.20BD9FD5-ONC1257003.00336351@cetenasa.es>
From: pbenito AT cemitec DOT com
Date: Mon, 16 May 2005 10:22:00 +0100
MIME-Version: 1.0

Hi,

I'm trying to use the serial port with Cygwin, and here is my problem:

I can successfully write on the line, but I need to switch the RTS and DTR
lines just AFTER the last byte is written in the line. I put the bytes that
I want in the line with the command Write and I wait for the last byte to
be written with tcdrain() and then I switch the RTS and RTS lines. But when
I see the signals in the oscilloscope I realized that the tcdrain call is
not waiting till the output buffer is empty and I switch the RTS and DTR
lines before I write all the bytes !! I attach my code, is it something
wrong with it or is there a problem with the tcdrain call in cygwin? On a
Linux box, tcdrain call seems to work fine...


 I'm running Cygwin v1.65 on a Windows XP SP2 machine.

Thanks for your help
Cheers

Pablo Benito



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


#define PORT "/dev/ttyS0"

int main() {

      int fd,status;
      char *msg ="Hello world!";
      struct termios options;

      // Open the serial port, and configuration
      fd = open(PORT, O_RDWR | O_NOCTTY  | O_SYNC);
      tcgetattr(fd,&options);
      options.c_cflag&= ~CSIZE;
      options.c_cflag |= CS8 | CLOCAL | CREAD;
      cfsetispeed(&options, B38400);
      cfsetospeed(&options, B38400);

      tcsetattr(fd,TCSANOW,&opciones);
      tcflush(fd,TCIOFLUSH);

      // Set the RTS and DTR lines to the initial value
      ioctl(fd,TIOCMGET,&status);
      status |= TIOCM_DTR;
      status &= ~TIOCM_RTS;
      ioctl( df, TIOCMSET, &status);

      // Send message to the line
      write(fd,msg,strlen(msg));

      // Waiting until the output buffer is empty ----------> Here comes
the problem
      tcdrain(fd);                        // tcdrain(fd) not waiting
????!?!??

      // Change back the RTS and DTR lines to their initial value
      ioctl(fd,TIOCMGET,&status);
      status &= ~TIOCM_DTR;
      status |= TIOCM_RTS;
      ioctl( df, TIOCMSET, &status);

      // Close the port
      close(fd);

      return 0;

}







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


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019