3
votes

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.

2

2 Answers

2
votes

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.

1
votes

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.