主题 : 关于 flush()  以及其用在串口的问题 复制链接 | 浏览器收藏 | 打印
级别: 侠客
UID: 6846
精华: 0
发帖: 55
金钱: 425 两
威望: 215 点
综合积分: 110 分
注册时间: 2009-06-19
最后登录: 2012-03-21
楼主  发表于: 2009-08-20 18:40

 关于 flush()  以及其用在串口的问题

1、听一位前辈说, flush() 函数可以实现 将缓冲区的数据串发至串口,直等串口将数据串全发送出去,该函数才返回值? 是这样吗? (我要用单IO口驱动去控制485的使能端,需要知道什么时候串口将数据发送完了。)

2、如果是这样,那打开串口设备文件是不是要用堵塞式打开?还是无所谓?

3、flush() 函数在哪个头文件里?  man flush 里没有写。

4、除了修改驱动(驱动我看都看不明白,谈不上修改了),有没有其它办法实现 RS485 的使能端控制?我指的是,串口发送数据时某IO口置高,发完就变回低电平,进入485接收状态。



谢谢版主及各位前辈们来指点!!!敬候!
级别: 侠客
UID: 6846
精华: 0
发帖: 55
金钱: 425 两
威望: 215 点
综合积分: 110 分
注册时间: 2009-06-19
最后登录: 2012-03-21
1楼  发表于: 2009-08-21 09:29

 Re:关于 flush() 以及其用在串口的问题

似乎已经解决了,用的  tcdrain() 函数实现了传输等待功能,就是不知道这函数的返回值的意思,MAN里也没讲,百度里也搜不到。呵呵。已经很满足了。
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
2楼  发表于: 2009-08-21 10:11

 Re:关于 flush() 以及其用在串口的问题

这是man tcdrain的输出, 耐心点看

...
       tcdrain() waits until all output written to the object referred to by fd has been transmitted.
...
RETURN VALUE
       cfgetispeed() returns the input baud rate stored in the termios structure.

       cfgetospeed() returns the output baud rate stored in the termios structure.

       All other functions return:

       0      on success.

       -1     on failure and set errno to indicate the error.
...
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."