Simple serial question...

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!

Reply to
twgray
Loading thread data ...

You just call them.

Nope. Where did you get that idea?

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

formatting link

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

--
Grant Edwards                   grante             Yow!  .. the HIGHWAY is
                                  at               made out of LIME JELLO and
 Click to see the full signature
Reply to
Grant Edwards

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.

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

Reply to
Alain Mosnier

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.

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).

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
 Click to see the full signature
Reply to
Grant Edwards

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. ;-)

Good to know. Thanks for the info.

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

Reply to
Alain Mosnier

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.

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

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              
 Click to see the full signature
Reply to
Grant Edwards

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

formatting link

Thanks for all the info.

Best regards,

Ala> >

Reply to
Alain Mosnier

Exactly.

--
Grant Edwards                   grante             Yow!  Why am I in this ROOM
                                  at               in DOWNTOWN PHILADELPHIA?
 Click to see the full signature
Reply to
Grant Edwards

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.

Reply to
Jim Jackson

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.

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
 Click to see the full signature
Reply to
Grant Edwards

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.