UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2004-07-30 05:09 PM

tiny
Member
Registered: 2004-06-21
Posts: 6

Re: Serial device buffer size

Hi!

I'm writing a program which communicates with a detector trough serial port.
Protocol prescribes 3 kinds of telegrams.  1 byte, 5 byte and max 40 bytes.
When I'm receiving telegrams I noticed read() is returning 8 or 16 bytes maximum.
I have to loop to receive the largest telegram. This complicates algorithm very
much and it is frankly anoying. Can I somehow solve this with 1 call to read
or are serial ports just like this and I have to write a function to read all data
from it.

thnx,
T.

Offline

#2 2004-07-30 07:51 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: Serial device buffer size

Well, sockets definitely behave that way, no matter what...  But,
for things like serial ports, I'd expect them to only do so if you
were using non-blocking I/O mode...  In that case, then certainly
they could behave such a way, as could nearly anything else
where all of the data may not be immediately available...  But, if
you're using blocking I/O, I'd expect the read() to block until your
full request was satisfied...  However, I suppose it might not do so
on a serial port... *shrug*  I haven't done much serial port coding in
a long time...

If you really wanted to wait until all data was available to read() in
one chunk, you could do ioctl(TIOCINQ) (or FIONREAD) until the
right number of bytes are there to read (probably with a short sleep
in between each test)...  But, I'm not sure how that's much better
than just doing the multiple read()'s, anyway...

Offline

#3 2004-07-31 05:30 PM

tiny
Member
Registered: 2004-06-21
Posts: 6

Re: Serial device buffer size

I use blocking I/O mode on serial port. I guess I'm going to do it
like I already started. With multiple reads until telegram is read.
Thanx for the info on ioctl().

T.

Offline

Board footer

Powered by FluxBB