Re: Blocking read() from a USB->Serial adapter.
- From: Bjoern Schliessmann <usenet-mail-0306.20.chr0n0ss@xxxxxxxxxxxxxxx>
- Date: Sat, 25 Nov 2006 01:49:03 +0100
Charles Sullivan wrote:
A blocking read() of more than one character from an actual RS232
serial port returns when the number of characters specified has
been read.
No. Have a look at man 2 read. Note the word "attempts".
| READ(2) Linux Programmer?s Manual READ(2)
|
| NAME
| read - read from a file descriptor
|
| SYNOPSIS
| #include <unistd.h>
|
| ssize_t read(int fd, void *buf, size_t count);
|
| DESCRIPTION
| read() attempts to read up to count bytes from file
| descriptor fd into the buffer starting at buf.
|
| If count is zero, read() returns zero and has no other
| results. If count is greater than SSIZE_MAX, the result is
| unspecified.
|
| RETURN VALUE
| On success, the number of bytes read is returned [...]
However I've found that a blocking read() of more than one
character from a USB->Serial adapter reads only the first
character before returning and I have to loop to read all the
characters.
- You have to do this no matter which FD you read from. If you
don't, 100 times the reading may succeed and the 101. time it may
not. Funny bugs may arise.
- Why is this a problem? Considering you use a serial interface with
blocking calls the overhead of a C loop shouldn't be a problem at
all.
Regards,
Björn
--
BOFH excuse #24:
network packets travelling uphill (use a carrier pigeon)
.
- Follow-Ups:
- Re: Blocking read() from a USB->Serial adapter.
- From: Charles Sullivan
- Re: Blocking read() from a USB->Serial adapter.
- References:
- Blocking read() from a USB->Serial adapter.
- From: Charles Sullivan
- Blocking read() from a USB->Serial adapter.
- Prev by Date: Blocking read() from a USB->Serial adapter.
- Next by Date: Re: Blocking read() from a USB->Serial adapter.
- Previous by thread: Blocking read() from a USB->Serial adapter.
- Next by thread: Re: Blocking read() from a USB->Serial adapter.
- Index(es):
Relevant Pages
|