I am trying to write a simple C serial communication program for Linux. I am confused about the blocking/non-blocking reads and VMIN/VTIME relationships.
My question
I'd recommend using vmin and vtime both 0 if you're using nonblocking reads. That will give you the behavior that if data is available, then it will be returned; the fd will be ready for select, poll, etc whenever data is available.
vmin and vtime are useful if you're doing blocking reads. For example if you're expecting a particular packet size then you could set vmin. If you want to make sure you get data every half second you could set vtime.
Obviously vmin and vtime are only for non-canonical mode (non-line mode)
My suspicion is that in nonblocking mode if you set vmin say to 5, then the fd will not be read-ready and read will return EWOULDBLOCK until 5 characters are ready. I don't know and don't have an easy test case to try, because all the serial work I've done has been either blocking or has set both to 0.