Read(2) 何時Return ?
在Raw data 的輸入程序模式下, 輸入的資料不會被組合成一行而輸入後的處理功能 (清除, 殺掉, 刪除, 等等.) 都不能使用. 這個模式有兩個控制參數: c_cc[VTIME] 設定字元輸入時間計時器, 及 c_cc[VMIN] 設定滿足read(2)的最低字元接收個數.
VMIN = 0 and VTIME = 0This is a completely non-blocking read - the call is satisfied immediately directly from the driver's input queue. If data are available, it's transferred to the caller's buffer up to nbytes and returned. Otherwise zero is immediately returned to indicate "no data". We'll note that this is "polling" of the serial port, and it's almost always a bad idea. If done repeatedly, it can consume enormous amounts of processor time and is highly inefficient. Don't use this mode unless you really, really know what you're doing.
如果 VMIN = 0 且 VTIME = 0, Non-bloking Read模式 , read(2) 立即Return目前已存在的字元組個數, 或者 Return 0 表示沒有資料, 你也可以用 fcntl(uartfd, F_SETFL, FNDELAY); => 設成Nonlblocking Mode
VMIN = 0 and VTIME > 0This is a pure timed read. If data are available in the input queue, it's transferred to the caller's buffer up to a maximum of nbytes, and returned immediately to the caller. Otherwise the driver blocks until data arrives, or when VTIME tenths expire from the start of the call. If the timer expires without data, zero is returned. A single byte is sufficient to satisfy this read call, but if more is available in the input queue, it's returned to the caller. Note that this is an overall timer, not an intercharacter one.如果 VMIN = 0 且 VTIME > 0, VTIME 將被當做逾時設定值. read(2) Return 的情況為讀取到單一字元, 或者超過 VTIME 所定義的時間 (t =VTIME *0.1 s). 如果超過 VTIME 所定義的時間, 則不會傳回任何字元.VMIN > 0 and VTIME > 0A read() is satisfied when either VMIN characters have been transferred to the caller's buffer, or when VTIME tenths expire between characters. Since this timer is not started until the first character arrives, this call can block indefinitely if the serial line is idle. This is the most common mode of operation, and we consider VTIME to be an intercharactertimeout, not an overall one. This call should never return zero bytes read.如果 VMIN > 0 且 VTIME > 0, VTIME 將被當做接收字元間隔的計時器. read(2) Return 的條件為 接收到 VMIN 個數的字元, 或兩個字元的間隔時間超過 VTIME 所定義的值. 計時器只會在第一個字元收到後才會啟動.且每讀到一個字元後會再重新計時.
VMIN > 0 and VTIME = 0This is a counted read that is satisfied only when at least VMIN characters have been transferred to the caller's buffer - there is no timing component involved. This read can be satisfied from the driver's input queue (where the call could return immediately), or by waiting for new data to arrive: in this respect the call could block indefinitely. We believe that it's undefined behavior if nbytes is less then VMIN.如果 VMIN > 0 且 VTIME = 0, VMIN 設定為 read(2) Return 的最低字元接收個數. 由於 TIME 是零, 所以計時器將不被使用.