天天看點

終端I/O之波特率函數

波特率(baud rate)是一個以往采用的術語,現在它指的是"位/秒"(bits per second)。雖然大多數終端裝置對輸入和輸出使用同一波特率,但是隻要硬體許可,可以将它們設定為兩個不同值。

#include <termios.h>

speed_t cfgetispeed(const struct termios *termptr);

speed_t cfgetospeed(const struct termios *termptr);

兩個函數的傳回值:波特率值

int cfsetispeed(struct termios *termptr, speed_t speed);

int cfsetospeed(struct termios *termptr, speed_t speed);

兩個函數的傳回值:若成功則傳回0,出錯則傳回-1

BB

兩個cfget函數的傳回值,以及兩個cfset函數的speed參數都是下列常量之一:B50、B70、B110、B134、B150、B200、B300、B600、B1200、B1800、B2400、B4800、B9600、B19200或B38400。常量B0表示"挂斷"。在調用tcsetattr時,如若将輸出波特率指定為B0,則數據機的控制線就不再起作用。