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]

Re: read() blocking and TIOCINQ


Ugh, top-posting... Reformatted.

On Tue, 5 Sep 2006, Ernesto Paiser wrote:

Igor Peshansky wrote:
> On Tue, 22 Aug 2006, Ernesto Paiser wrote:
>
> > Hello Corinna,
>
> FYI, this is a mailing list, and unless you're replying to a specific
> message, you're actually talking to many people.
>
> > I have problems with read() function blocking and
> > waiting for characters on serial line with cygwin:
> >
> > Here are some code fragments:
> > ========================================================
> > fd = open(sl, O_RDWR | O_NOCTTY | O_NONBLOCK | O_NDELAY)
> >
> > newpio.c_cflag = brate | CS8 | CLOCAL | CREAD;
> > newpio.c_iflag = IGNPAR | ICRNL;
> > newpio.c_oflag = 0;
> > newpio.c_lflag = 0;
> > newpio.c_cc[VTIME]    = 1;
> > newpio.c_cc[VMIN]     = 0;
> > ...
> >
> > n = ioctl(fd, TIOCINQ, &n); //It gives me an error (return -1) why??!!!
> >
> > and
> >
> > n = read(fd, buffer, 1);  <<< HERE IS BLOCKING!!!
> > ========================================================
> >
> > TIOCINQ is working on CYGWIN,
> >
> > Is there another way to solve this problem???
>
> Please post a complete compilable test case that reproduces the
> problem. For example, in the above code, it's unclear what the
> variable sl contains (and I suspect it contains "COM1", which is a
> no-no -- you should be using "/dev/ttyS0").
> 	Igor

Hello Igor,
Sorry for my incomplete question.
I attach to you the following file that could be compiled with gcc in
CYGWIN.
Accepted commands start by '?' character, and when the device is not
connected on the serial line the function read(...) blocks:


DEVICE test program -------------------

Type your commands ('.' to quit):
>> Enter command: ?ver


Then, blocked....:-((



Note that in our computers the serial line name is COMn not /dev/ttySn.

And therein lies your problem. When you use COMn, you get access to the raw Windows device, without Cygwin's POSIX emulation, so it's not surprising that ioctl() doesn't work.

I tried before with /dev/ttySn and I receive file not found as answer.

That's probably because COMn = /dev/ttyS{n-1} (e.g., COM1 -> /dev/ttyS0). HTH, Igor -- http://cs.nyu.edu/~pechtcha/ |\ _,,,---,,_ pechtcha@cs.nyu.edu | igor@watson.ibm.com ZZZzz /,`.-'`' -. ;-;;,_ Igor Peshansky, Ph.D. (name changed!) |,4- ) )-,_. ,\ ( `'-' old name: Igor Pechtchanski '---''(_/--' `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-. Meow!

"Las! je suis sot... -Mais non, tu ne l'es pas, puisque tu t'en rends compte."
"But no -- you are no fool; you call yourself a fool, there's proof enough in
that!" -- Rostand, "Cyrano de Bergerac"

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


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