public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* RE: tcflush hang problem
@ 2003-11-03  9:59 H. Henning Schmidt
  0 siblings, 0 replies; 5+ messages in thread
From: H. Henning Schmidt @ 2003-11-03  9:59 UTC (permalink / raw)
  To: cygwin

I am pretty certain the the problem which is discussed in this thread 
has already been reported in
http://sources.redhat.com/ml/cygwin/2003-03/msg01529.html

There is obviously an input buffer, which overflows if you keep an open 
filedesc. on a serial port and let some external system generate input 
data on that port while your own app does not read them away from there 
fast enough. The message referenced above (from March 2003) also 
contains a reliable way to reproduce this problem. My guess is, that the 
tcflush() itself is probably not guilty in any way, it just helps 
reproducing the problem.

;Henning



--
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] 5+ messages in thread

* Re: tcflush hang problem
       [not found] ` <Pine.GSO.4.56.0310131444410.791@eos>
@ 2003-10-14  8:02   ` Martin Farnik
  0 siblings, 0 replies; 5+ messages in thread
From: Martin Farnik @ 2003-10-14  8:02 UTC (permalink / raw)
  To: cygwin

Thank for answer.

I replace tcflush(fd,TCIFLUSH) by
do {
 err = read(fd,iobuffer,1000)
} while(err>0)

and it work OK on Win98.

I still have problem on Windows2000Sp2. 
It seem that it hangs  in functions:
tcsetattr(fd,TCSANOW,&newtio);
read(fd,iobuffer,1000);
write(fd,iobuffer,10);

Strange thing is, that it hangs from my point of view randomly.
Becase sometimes is operation successfully and other times it hangs (Windows:program is not responding).

thank for help
Marty


> Cygwin's current tcflush implimentation is rather crude.  Although, it may
> not be possible to do any better.  PTC.
> 
>   if (queue == TCIFLUSH || queue == TCIOFLUSH)
>     /* Input flushing by polling until nothing turns up
>        (we stop after 1000 chars anyway) */
>     for (int max = 1000; max > 0; max--)
>       {
>         COMSTAT st;
>         if (!PurgeComm (get_handle (), PURGE_RXABORT | PURGE_RXCLEAR))
>           break;
>         low_priority_sleep (100);
>         if (!ClearCommError (get_handle (), &ev, &st) || !st.cbInQue)
>           break;
>       }
> 
> So, your not really hung.  Just stuck for a long time.
> 
> As a work around, tell the device to shut up first, then flush.
> 
> On Mon, 13 Oct 2003, Martin Farnik wrote:
> 
> > Hi.
> > I use CYGWIN_98-4.10 mine 1.5.5(0.94/3/2) 2003-09-20 16:31 i686 uknown
> > unknown Cygwin
> >
> > First i try to describe a situation:
> > I have a device which is connected with computer thru serial line.
> > Device is still sending data.These data isn't for my program.I have
> > open com port and let them go into buffer . When a want to talk with
> > device i flush input buffer, send it a command paket and device stop
> > sending data and wait for my next command.
> > Problem is when I want to flush INPUT buffer before I send a command. In
> > this point it hangs, maybe for buffer full.
> > Here is piece of code:
> >
> > -----I open port when i start program -----
> >
> >  fd = open(PORT0, O_RDWR | O_NOCTTY );
> >  tcgetattr(fd,&oldtio); /* save current port settings */
> >
> >         bzero(&newtio, sizeof(newtio));
> >         newtio.c_cflag = CS8 | CLOCAL | CREAD | CSTOPB;
> >         newtio.c_iflag = 0;
> >         newtio.c_oflag &= ~OPOST;
> >         newtio.c_lflag = 0;
> >
> >         newtio.c_cc[VTIME]    = 1;
> >         newtio.c_cc[VMIN]     = 0;
> >
> > 	cfsetispeed(&newtio,B19200);
> > 	cfsetospeed(&newtio,B19200);
> >         tcflush(fd, TCIFLUSH);
> >         tcsetattr(fd,TCSANOW,&newtio);
> > -------------------------------------------------
> > --this code is execute when a want to talk with device----
> >
> >        tcflush(fd, TCIFLUSH);	    <--------- in this point where it hangs
> > 	err = write (fd,iobuffer,10);
> >
> 
> -- 
> Brian Ford
> Senior Realtime Software Engineer
> VITAL - Visual Simulation Systems
> FlightSafety International
> Phone: 314-551-8460
> Fax:   314-551-8444

--
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] 5+ messages in thread

* Re: tcflush hang problem
@ 2003-10-13 20:10 Brian Ford
  0 siblings, 0 replies; 5+ messages in thread
From: Brian Ford @ 2003-10-13 20:10 UTC (permalink / raw)
  To: cygwin

Sorry, my fingers aren't working.  I keep accidentally replying to the
sender rather than/in addition to the list.

Cygwin's current tcflush implimentation is rather crude.  Although, it may
not be possible to do any better.  PTC.

  if (queue == TCIFLUSH || queue == TCIOFLUSH)
    /* Input flushing by polling until nothing turns up
       (we stop after 1000 chars anyway) */
    for (int max = 1000; max > 0; max--)
      {
        COMSTAT st;
        if (!PurgeComm (get_handle (), PURGE_RXABORT | PURGE_RXCLEAR))
          break;
        low_priority_sleep (100);
        if (!ClearCommError (get_handle (), &ev, &st) || !st.cbInQue)
          break;
      }

So, your not really hung.  Just stuck for a long time.

As a work around, tell the device to shut up first, then flush.

On Mon, 13 Oct 2003, Martin Farnik wrote:

> Hi.
> I use CYGWIN_98-4.10 mine 1.5.5(0.94/3/2) 2003-09-20 16:31 i686 uknown
> unknown Cygwin
>
> First i try to describe a situation:
> I have a device which is connected with computer thru serial line.
> Device is still sending data.These data isn't for my program.I have
> open com port and let them go into buffer . When a want to talk with
> device i flush input buffer, send it a command paket and device stop
> sending data and wait for my next command.
> Problem is when I want to flush INPUT buffer before I send a command. In
> this point it hangs, maybe for buffer full.
> Here is piece of code:
>
> -----I open port when i start program -----
>
>  fd = open(PORT0, O_RDWR | O_NOCTTY );
>  tcgetattr(fd,&oldtio); /* save current port settings */
>
>         bzero(&newtio, sizeof(newtio));
>         newtio.c_cflag = CS8 | CLOCAL | CREAD | CSTOPB;
>         newtio.c_iflag = 0;
>         newtio.c_oflag &= ~OPOST;
>         newtio.c_lflag = 0;
>
>         newtio.c_cc[VTIME]    = 1;
>         newtio.c_cc[VMIN]     = 0;
>
> 	cfsetispeed(&newtio,B19200);
> 	cfsetospeed(&newtio,B19200);
>         tcflush(fd, TCIFLUSH);
>         tcsetattr(fd,TCSANOW,&newtio);
> -------------------------------------------------
> --this code is execute when a want to talk with device----
>
>        tcflush(fd, TCIFLUSH);	    <--------- in this point where it hangs
> 	err = write (fd,iobuffer,10);
>

-- 
Brian Ford
Senior Realtime Software Engineer
VITAL - Visual Simulation Systems
FlightSafety International
Phone: 314-551-8460
Fax:   314-551-8444

--
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] 5+ messages in thread

* tcflush hang problem
@ 2003-10-13  9:47 Martin Farnik
  0 siblings, 0 replies; 5+ messages in thread
From: Martin Farnik @ 2003-10-13  9:47 UTC (permalink / raw)
  To: cygwin

I forgot :

#define PORT0 "/dev/ttyS0"

Marty

--
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] 5+ messages in thread

* tcflush hang problem
@ 2003-10-13  6:59 Martin Farnik
       [not found] ` <Pine.GSO.4.56.0310131444410.791@eos>
  0 siblings, 1 reply; 5+ messages in thread
From: Martin Farnik @ 2003-10-13  6:59 UTC (permalink / raw)
  To: cygwin

Hi.
I use CYGWIN_98-4.10 mine 1.5.5(0.94/3/2) 2003-09-20 16:31 i686 uknown unknown Cygwin

First i try to describe a situation:
I have a device which is connected with computer thru serial line.
Device is still sending data.These data isn't for my program.I have open com port and let them go into buffer . When a want to talk with device i flush input buffer,
send it a command paket and device stop sending data and wait  for my next command.
Problem is when I want to flush INPUTbuffer before I send a command. In this point it hangs, maybe for buffer full.
Here is piece of code:

-----I open port when i start program -----

 fd = open(PORT0, O_RDWR | O_NOCTTY );
 tcgetattr(fd,&oldtio); /* save current port settings */
        
        bzero(&newtio, sizeof(newtio));
        newtio.c_cflag = CS8 | CLOCAL | CREAD | CSTOPB;
        newtio.c_iflag = 0;
        newtio.c_oflag &= ~OPOST;
        newtio.c_lflag = 0;
         
        newtio.c_cc[VTIME]    = 1;  
        newtio.c_cc[VMIN]     = 0;   
        
	cfsetispeed(&newtio,B19200);
	cfsetospeed(&newtio,B19200);
        tcflush(fd, TCIFLUSH);
        tcsetattr(fd,TCSANOW,&newtio);
-------------------------------------------------
--this code is execute when a want to talk with device----

       tcflush(fd, TCIFLUSH);	    <--------- in this point where it hangs
	err = write (fd,iobuffer,10);


thank for help
			Marty

--
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] 5+ messages in thread

end of thread, other threads:[~2003-11-03  9:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-03  9:59 tcflush hang problem H. Henning Schmidt
  -- strict thread matches above, loose matches on Subject: below --
2003-10-13 20:10 Brian Ford
2003-10-13  9:47 Martin Farnik
2003-10-13  6:59 Martin Farnik
     [not found] ` <Pine.GSO.4.56.0310131444410.791@eos>
2003-10-14  8:02   ` Martin Farnik

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