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



On 2006-11-25, Charles Sullivan <cwsulliv@xxxxxxxxxxxx> 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".

I can understand the "attempts to read" for a non-blocking
read - returning fewer characters than specified if the
characters aren't immediately available to be read.

But I had the impression that a blocking read is supposed to
block forever or until it either reads the specified number of
characters or is interrupted.

That's the way most character drivers work, but that's not
required by the documented API.

You're saying maybe it will and maybe it won't and that's to
be expected.

Yes, that's what he's saying.

Not a problem. I am just puzzled why reading from the adapter
differs from reading from an actual serial port.

Good question. In both cases you're calling the same piece of
code in the tty line discipline layer. If you really do want
to know why the behavior differs, you're probably going to have
to examine the tty line discipline read() system call handler
and the code for the 16550 driver and the usb-serial driver.

BTW, the number of characters to be read is never more than
10.

OK, but that's moot.

--
Grant Edwards
grante@xxxxxxxx

.



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)