RS-232 Serial communication and parallel Communication with Linux

  • Thread starter Ing. Alberto Maldonado
  • Start date
I

Thread Starter

Ing. Alberto Maldonado

Dear List:
If You have some Literature (Manuals, or Web sites ) for this special topic to connect RS-232 Serial and Parallel Communications in Linux . I
need not only the hardware communications, specially the programmation in Linux to connect these ones. It can be with Language C++ or if it is possible with Assembler.

Thank You very much for your Attention.

Alberto Maldonado
 
T

Thomas.hergenhahn

There exists texts called "Serial-HOWTO" and "Serial-Programming-HOWTO". They came with my distro (SuSE 7.2) and I find them in: /usr/share/doc/howto/en/Serial-(Programming-)Howto1.html.
If you don't have them, you should search google for them.
Generally, there are two things: data exchange and control of settings. Data exchange is done by writing to a file or file descriptor as to any other file. I prefer to write to file descriptors using read(2) and write(2) calls.
When you write (fprintf) to a FILE*, libc puts your data into buffers first. You would have to flush the buffer to trigger the real data output.

Control of settings(like baudrate setting and many more is done via the ioctl() system calls.
See man ioctl().
Additionally, there are tcsetattr() and tcgetattr() which will use structs containing multiple settings. There are man pages for these functions too.
It is best to programm in C (or C++) as this allows you to use the hedaer files and the constants and structs. Using them gives you the possibility to simply recompile your program if they would ever change with kernel development.
One last advice: The normal bevaviour of the kernel is to interpret certain characters as flow control, translate carriage reeturn to linefeed and return data after line feed.
This is normally NOT what you want if you transmit random bytes over a serial line.
You can change this using manipulating iflags and oflags in the termios(3) struct.
HTH
If you have more questions contact: "[email protected]", mailto:[email protected]
 
K
Hi Alberto,

I think it may be trivial to do that, and you could probably use whatever language you choose, or even a shell script (or command line). Just connecting a serial device to a "line printer" device via a pipe, and turning off output buffering, ought to do the job. I'd have to mess with it a bit to get it right, but in Perl this would be a 1 to 3 line program, I would think.

I'm not sure what your goal is, but this sort of thing could be used to stream serial data directly to a printer, for example.

Ken

--
Ken Irving <[email protected]>
 
Ken Irving:
> in Perl this would be a 1 to 3 line program, I would think.

Yeah, but in Perl most anything is a 1 to 3 line program (though complicated things, like public-key cryptograpy, may take 4 lines).

> AlbertoMaldonado wrote:
> > If You have some Literature (Manuals, or Web sites ) for this
> > special topic to connect RS-232 Serial and Parallel Communications
> > in Linux .

I take it you've been through the HOWTOs? Apart from the obvious ones (Serial, Printing), look also at the Coffee mini-HOWTO, which covers low-level access to the parallel port.

(It's called the Coffee HOWTO because it talks about connecting a coffee machine to linux - via the parallel port.)

> > It can be with Language C++ or if it is possible with Assembler.

Not sure why you'd use assembler - for the most part, gcc will produce better assembly than you can, because of things like keeping the pipelines full. In any case, code in C++ first, then profile, then re-code critical parts in assembly if necessary.

Jiri
--
Jiri Baum <[email protected]> http://www.csse.monash.edu.au/~jirib
MAT LinuxPLC project --- http://mat.sf.net --- Machine Automation Tools
 
Top