Simple serial question...

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
How can I send and receive binary packets of data using the standard
Linux file i/o functions: open, write, read, close?  It appears that
write and read are ascii only functions.

Help!


Re: Simple serial question...

Quoted text here. Click to load it

You just call them.

Quoted text here. Click to load it

Nope.  Where did you get that idea?

You'll probably want to put the tty driver into "raw" mode:

  http://www.easysw.com/~mike/serial /

NB: Don't use the Linux serial programming HOWTO.

--
Grant Edwards                   grante             Yow!  .. the HIGHWAY is
                                  at               made out of LIME JELLO and
We've slightly trimmed the long signature. Click to see the full one.
Re: Simple serial question...
Quoted text here. Click to load it
You can also have a look at the source code I included in my answer to
another thread in the same group called "need a sample code". In it, I
send an receive a character "A". But you can replace it with a pointer
to whatever variable of binary type that you want, and use the sizeof()
operator as the third argument of read() or write(). Be aware of the
byte ordering issue though: your source and destination might order the
bytes differently. This is not a problem if both source and destination
are Linux, which is always little-endian, as far as I know (less
significant byte first). Otherwise, you need to use the functions
htons(), htonl(), ntohs() and ntohl() to convert values back and forth
before and after transmitting them.
Quoted text here. Click to load it
Just out of curiosity, why is that? Anything specific that would be
wrong in that HOWTO? I'm rather using the "Serial Programming Guide
for POSIX Operating Systems" which is more recent myself, but I would
still be interested to hear what's wrong in that HOWTO.

Regards,

Alain

Re: Simple serial question...

Quoted text here. Click to load it

Wha?

There are plenty of big-endian architectures running Linux:

  SPARC
  PPC  
  68000
  IBM-370 (and I presume z-series),
  H8/300
  ARM
  etc.

I suspect that the majority of Linux-supporting architectures
are big-endian, even though most Linux machines are
little-endian.

Quoted text here. Click to load it

Yes.  Mainly the code used to open devices.  I have vague
recollections of problems with the way some of the termios
stuff is done too, but I can't remember the details.  There are
also large amounts of stuff that's just not there (e.g.
accessing modem control/status lines).

Quoted text here. Click to load it

You're the only one, then.  Corrections and entirely new
chapters have been submitted but have been ignored.

--
Grant Edwards                   grante             Yow!  The PINK SOCKS were
                                  at               ORIGINALLY from 1952!! But
We've slightly trimmed the long signature. Click to see the full one.
Re: Simple serial question...
Quoted text here. Click to load it
All right, I guess I was just talking about x86 then.

Anyway, I guess my point about byte ordering was even more relevant that
I thought. ;-)
Quoted text here. Click to load it
Good to know. Thanks for the info.
Quoted text here. Click to load it
Do you mean that people don't know that document? I found it immediately
at my first Google search about Linux serial programming (actually, the
HOWTO points to it). I think that document fills a surprising hole in
books like "Advanced programming in the UNIX environment", "Advanced
UNIX programming" and "UNIX network programming", which are very good
books otherwise.

Regards,

Alain

Re: Simple serial question...

Quoted text here. Click to load it

No, I mean that people have sent in corrections for the HOWTO,
but those corrections are ignored.  I wrote an entire new
chapter on how to read/write modem control/status lines and
submitted that.  Nothing happened.  Despite the fact that
people send in corrections and new material, the HOWTO hasn't
been updated in 7 years.  It was out-of date 7 years ago, and
even more so now.  It needs to be removed from the website.

It's incomplete, obsolete and misleading.

Quoted text here. Click to load it

I know.  It's quite unfortunate that it's so easy to find.

Quoted text here. Click to load it

I'm not saying there's no need for serial programming
documentation, I'm saying that the HOWTO does a bad job of
meeting that need.  The Posix serial programming guide is much,
much better.  The serial HOWTO _could_ be better, and those of
us who do serial stuff for a living have tried (and failed) to
make it better.  Now we've just given up on it.

--
Grant Edwards                   grante             Yow!
                                  at              
We've slightly trimmed the long signature. Click to see the full one.
Re: Simple serial question...
Hi Grant,

Now I get you, we misunderstood each other.

Your answer "You're the only one, then..." was to my writing "I'm rather
using the "Serial Programming Guide for POSIX Operating Systems" which
is more recent myself, but I would still be interested to hear what's
wrong in that HOWTO."

I thought you answered to my using of the POSIX guide, but you actually
meant that nobody is interested to hear what's wrong in the HOWTO.

So as a summary, you're saying that the HOWTO is outdated, and that
people should use the POSIX guide instead
(http://www.easysw.com/~mike/serial /).

Thanks for all the info.

Best regards,

Alain Mosnier

Grant Edwards wrote:
Quoted text here. Click to load it

Re: Simple serial question...

Quoted text here. Click to load it

Exactly.

--
Grant Edwards                   grante             Yow!  Why am I in this ROOM
                                  at               in DOWNTOWN PHILADELPHIA?
We've slightly trimmed the long signature. Click to see the full one.
Re: Simple serial question...

Quoted text here. Click to load it

Take it over. Correct it, add you addenda, and put it up onyour own
website and publicise it. Submit it back to to the LDP as a new document.

Sometime authors disappear, like software maintainers, but others can step
forward and keep things rolling.

Re: Simple serial question...
Quoted text here. Click to load it


Firstly, I've submitted corrections and new sections.  My
submissions were ignored.  Secondly, the entire document is now
redundant and just needs to be deleted.

Quoted text here. Click to load it

Somebody has already written a far better document.  I see no
need to try to compete with it.  It's just too bad the serial
HOWTO won't "go away".

--
Grant Edwards                   grante             Yow!  Kids, don't gross me
                                  at               off... "Adventures with
We've slightly trimmed the long signature. Click to see the full one.

Site Timeline