Re: Blocking read() from a USB->Serial adapter.



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)

.



Relevant Pages

  • Re: Serial port monitoring
    ... if (!characters) return; ... you would not want to use blocking I/O on a serial port. ... I would then have a loop that checks for char in serial buffer. ...
    (microsoft.public.vc.mfc)
  • Re: keybd_event problems.
    ... applications that use it for various things like serial port wedging. ... These don't map to the ascii table at all, ... lower case non language characters? ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: display output from serial port device
    ... If your program fails to open the serial port, ... If you do want parity, restore INPCK, but also add PARENB to ... always get the right number of characters. ...
    (comp.os.linux.development.system)
  • RE: SerialPort read&write members display string value above 127 as "?
    ... Serial Port Class methods of Read and Write default to ASCII code ... namespace EncodeTest1 ... // A Unicode string with two characters outside an 8-bit code ... "This unicode string contains two characters " + ...
    (microsoft.public.dotnet.framework)
  • Re: C-MAX CME8000-BUS problems
    ... If you connect the CME-8000 module directly to the PIC's serial port ... (assuming you take care of the voltage converter circuitry), ... and this takes care of the weird one-wire serial interface that C- ... the characters I sent looped back to me. ...
    (comp.arch.embedded)