分类:
2008-06-21 11:54:47
In non-canonical input processing mode, input is not assembled into lines and input processing (erase, kill, delete, etc.) does not occur. Two parameters control the behavior of this mode: c_cc[VTIME] sets the character timer, and c_cc[VMIN] sets the minimum number of characters to receive before satisfying the read.
If MIN > 0 and TIME = 0, MIN sets the number of characters to receive before the read is satisfied. As TIME is zero, the timer is not used.
If MIN = 0 and TIME > 0, TIME serves as a timeout value. The read will be satisfied if a single character is read, or TIME is exceeded (t = TIME *0.1 s). If TIME is exceeded, no character will be returned.
If MIN > 0 and TIME > 0, TIME serves as an inter-character timer. The read will be satisfied if MIN characters are received, or the time between two characters exceeds TIME. The timer is restarted every time a character is received and only becomes active after the first character has been received.
If MIN = 0 and TIME = 0, read will be satisfied immediately. The number of characters currently available, or the number of characters requested will be returned. According to Antonino (see contributions), you could issue a fcntl(fd, F_SETFL, FNDELAY); before reading to get the same result.
这样我们可以看出TIME是一个定时器而时间估计是100ms为单位,而MIN是一个字符间间植,
当我把
newtio.c_cc[VMIN]=0;
newtio.c_cc[VTIME]=31;
时发现31个的串可收,但如果其他的串小于31,串口会被中断堵塞
这样需要一个定时器来让他重新关闭,并把不足31的字符返回给buf里
所以可以写成
newtio.c_cc[VMIN]=1;
newtio.c_cc[VTIME]=31;
这样字符范围就在0-31之间的任意长度并在定时100ms内可以在次读去而不造成主塞现象
OK今天的一个小问题希望能给做arm 通讯的朋友一点帮助!