#include
speed_t cfgetispeed (const struct termios* termptrl );
speed_t cfgetospeed (const struct termios *termptr) ;
两个函数的返回值:波特率值
int cfsetispeed ( struct terrnios *tennptr, speed_t speed ) ;
int cfsetospeed ( struct terrnios *termptr, speed_t speed ) ;
两个函数的返回值:若成功则返回0,着出错则返回-1
两个cfget 函数的返回值,以及两个cfset 函数的speed 参数都是下列常量之:B50 、B7 5 、BllO 、B134 、Bl 50 、B2 00 、B3 00 、B6 00 、B12 00 、B180 0 、B2 4 00 、B4 800 、B9 6 00 、Bl9200或B38400。常量B0表示“挂断”。在调用tcsetattr时,如若将输出波特率指定为 B0 ,则调制解调器的控制线就不再起作用。
大多数系统定义了 另外的波特率值,例如B57600 以及B115200.
使用这些函数时,应当理解输入、输出波特率是存放在图 18-3所示的设备termios结构中的。在调用任一cf get函数之前,先要用tcgetattr获得设备的termios结构。与此类似,在调用任一 cfset 函数后,应将波特率设置到termios结构中。为使这种更改影响到设备,应当调用 tcsetattr 函数。如果所设置的波特率有错,则在调用tcsetattr之前,不会发现这种错误。这4个波特率函数使应用程序不必考虑 具体实现在 termios结构中表示波特率的不同方法。 BSD派生的平台趋向于存放波特率的数值(例如9600波特就存放为9600 ) ,同时Linux和系统V 派生的平台趋向于以位屏蔽方式表示波特率。从cf get 函数得到的以及向cf set传送的速度值 与它们存放在termios结构中的一样。
Copyright 2023 fuwu029.com赣ICP备2022008914号-4