PDA

View Full Version : Programming RS232 ports



firdooze
March 15th, 2008, 05:53 AM
Hi!

I am doing a program to read data sent to the RS232 port on an Ubuntu machine. I hope to do it in C. I've been looking around and I can't seem to find a good guide to help me start doing the program.

Can someone point me to the right direction? Thanks!

duuchung
March 15th, 2008, 07:00 AM
Have you done all the searches? I posted the same question but I used PERL several months ago here in this forum. People have given me all the clues.

Shin_Gouki2501
March 15th, 2008, 11:19 AM
years ago i used java and java comm api todo that worked pretty much nice for me:
http://java.sun.com/products/javacomm/

themusicwave
March 15th, 2008, 04:11 PM
years ago i used java and java comm api todo that worked pretty much nice for me:
http://java.sun.com/products/javacomm/

I used Java and the java comm api about a month ago. It was fairly straight forward to use, and has the benefit of being cross platform.

I have no idea what C API to use for serial access.

stroyan
March 15th, 2008, 06:21 PM
You want to review this document for using C to access serial ports.
http://www.faqs.org/docs/Linux-HOWTO/Serial-Programming-HOWTO.html

You might also want to refer to this one for language independent background on the workings of RS232 ports.
http://tldp.org/HOWTO/Serial-HOWTO.html

dwblas
March 17th, 2008, 01:48 AM
Find an existing-already tested and debugged app. In Python there is pyserial http://pyserial.sourceforge.net/ There has to be apps already out there for other languages as well.

supirman
March 17th, 2008, 03:06 AM
What kind of data are you planning to read? Using a serial port in linux is quite easy. All you really need to do is configure the port and then read the data. You treat a serial port just like a regular file to read the data.

Essentially, you'd have a sequence like:

open() the file /dev/ttyS0 (or the device file for your serial port)

call tcsetattr() on the file descriptor to set parameters

read() from the file descriptor to read the incoming data