delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/01/19/17:01:12

X-Spam-Check-By: sourceware.org
Message-ID: <005201c73c15$464b7ac0$3001a8c0@Asymmetric>
From: "Enrique Perez-Terron" <enrio AT online DOT no>
To: "Florent Morin" <morinflorent AT gmail DOT com>, <cygwin AT cygwin DOT com>
References: <25e2d6fe0701180840k6bd5b27di630bca3a0a010ac3 AT mail DOT gmail DOT com> <45AFA5A5 DOT 3406349E AT dessent DOT net> <25e2d6fe0701180902m35903447w69c1ff91ef4eb8d1 AT mail DOT gmail DOT com> <25e2d6fe0701190139r5e18aa89jc96e2229caaf8649 AT mail DOT gmail DOT com> <25e2d6fe0701190140u17a989fcva9e3cbf1d935ebd4 AT mail DOT gmail DOT com>
Subject: Re: cygwin 1.5.23-2 : I can't use select() with serial device and socket
Date: Fri, 19 Jan 2007 23:00:45 +0100
MIME-Version: 1.0
X-Mailer: Microsoft Outlook Express 6.00.2900.3028
X-DCC-nextmail-Metrics: mail45.nsc.no 10045; Body=0 Fuz1=0 Fuz2=0
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
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

You don't show the complete output of the two programs. Do you have a device 
connected to the serial port that echoes the data written? Or  a device that 
provides some data to read? With the first program, how many bytes does it 
read?

Is the serial port set driver set to generate echo locally? On Linux? On XP? 
On both?

> The second code write on socket, but it says that serial port isn't ready 
> to read.

Your select statement appears to tell that there are no data available to 
read on the serial port.

You should normally write select() read-write loops so that file descriptors 
are entered into the write_fdset only if there is something to write. 
Otherwise the program will be running in a tight loop because the the 
select() returns telling that (e.g) the serial_fd is ready to accept more 
data. The point in using select is to have the program sleep until there is 
something to do.

  while(up_is_open || down_is_open)
  {
    if (up_is_open) {
      has_data(up_buffer))
        FD_SET(space_fd, &write_fdset);
      else
        FD_SET(earth_fd, &read_fds);
    }

    if (down_is_open) {
      if (has_data(down_buffer))
        FD_SET(earth_fd, &write_fdset);
      else
        FD_SET(space_fd, &read_fdset);
    }

    ready_fds = select(max_fd, &read_fdset, &write_fdset, NULL, NULL);
    if (ready_fds < 0) {...}

    if (FD_ISSET(earth_fd, &write_fdset) {...}
    if (FD_ISSET(space_fd, &write_fdset) {...}
    if (FD_ISSET(earth_fd, &read_fdset) {...}
    if (FD_ISSET(space_fd, &read_fdset) {...}
  }

Regards 



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