對於波特率的設置通常使用cfsetospeed和cfsetispeed函數來完成。獲取波特率信息是通過cfgetispeed和cfgetospeed函數來完成的。
cfsetospeed函數
頭文件:
#include
函數原型:
int cfsetospeed(struct termios *termptr, speed_t speed);
參數:
struct termios *termptr - 指向termios結構的指針
speed_t speed - 需要設置的輸出波特率
返回值:
如果成功返回0,否則返回-1
cfsetispeed函數
頭文件:
#include
函數原型:
int cfsetispeed(struct termios *termptr, speed_t speed);
參數:
struct termios *termptr - 指向termios結構的指針
speed_t speed - 需要設置的輸入波特率
返回值:
如果成功返回0,否則返回-1
cfgetospeed函數
頭文件:
#include
函數原型:
speed_t cfgetospeed(const struct termios *termptr);
參數:
const struct termios - 指向termios結構的指針
返回值:
返回輸出波特率
cfgetispeed函數
頭文件:
#include
函數原型:
speed_t cfgetispeed(const struct termios *termptr);
參數:
const struct termios *termptr - 指向termios結構的指針
返回值:
返回輸入波特率
波特率常量:
CBAUD 掩碼
B0 0波特
B50 50波特
B75 75波特
B110 100波特
B134 134波特
B150 150波特
B200 200波特
B300 300波特
B600 600波特
B1200 1200波特
B1800 1800波特
B2400 2400波特
B9600 9600波特
B19200 19200波特
B38400 38400波特
B57600 57600波特
B115200 115200波特