简体   繁体   中英

How to setup the serial port?

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.

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.

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.

在这个链接: http//www.easysw.com/~mike/serial/serial.html你会发现一堆有用的信息。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM