views:

63

answers:

2

Hi,

I'm using Linux OS as a programming platform. And I want to create a program that uses serial(/dev/ttyS0) port as a communication medium. I already know how to open, read, write and close the serial port using standard Linux function.

Now my question is how can I able to setup the serial port? What I mean is I want to change the setting values of a serial device programmatically.

Many thanks.

+1  A: 

The man page you need to read is termios(3). It describes the POSIX functions to manipulate the TTY line discipline, which is where the serial parameters are.

camh
+1  A: 

You will need to call tcgetattr() and tcsetattr() to change the baud rate, stop bits, etc.

When dealing with device ports, it's often a good idea to use I/O with timeouts. See select() and poll() for that.

James Roth