|
-
August 14th, 2005, 11:38 AM
#2
Hi
Essentially, in Linux you can access the serial ports /dev/ttyS?
(generic name) like a file, ie you get a filedescriptor with open(),
you write to it with fputc(), you close it with close(). The difficulty
lies in the proper choice of the settings and the communication
options.
Once, I wrote a controller program for a model railway, and
the device specification were not complete - or I did not understand
it properly - it took me ages to avoid the trains crashing all the time 
Since you know the basics, have a look at linux.com-HOWTO's[1,2].
But I suggest you to analyse a serial port test program[3] step by step,
which compiles perfectly using
Code:
> gcc -o com com.c
with a default installation of some linux distribution. Go through the
source code, and try to understand what they are doing.
You can use the program to send bit's to tty2, or you might try to
"cp /dev/ttyS1 /dev/tty2" in a virtual console and check, whether
the communication works (I have not tested this, but from what I
remember...), or connect two PC's with a null-modem cable.
Notabene: I am not going to discuss the level of abstraction in
the approach I suggested here, nor do I comment on the "control"
over the ports provided by various OS's. Depending on the amount
of time you want to spend into your project, I would recommend
to use the environment you are most familiar with.
Cheers
[1] http://www.linux.com/howtos/Serial-HOWTO.shtml#toc11
[2] http://www.linux.com/howtos/Serial-P...TO/index.shtml
[3] http://www.comptechdoc.org/os/linux/...pgcserial.html
If the only tool you have is a hammer, you tend to see every problem as a nail.
(Abraham Maslow, Psychologist, 1908-70)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|