I'm writing a console application under Ubuntu that uses the serial port. It needs to read and write from the serial port at 60 Hz.
I find that the call to read() is often, but not always, slow. I have set O_NDELAY, so often it returns immediately (great). Sometimes it takes up to 50 ms to finish, and that is too slow for my application. Before calling read(), I check the number of chars available, so it should not be waiting for data.
What is read() doing that takes so long? How can I speed it up?
Options on the port are:
options.c_cflag |= (CLOCAL | CREAD);
options.c_cflag &= ~PARENB;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
options.c_iflag &= ~IXON;
options.c_oflag = 0;
edit: I'd been using select() earlier but it turned out to be orthogonal to the question. Updated with my latest information.