I am opening a /dev/ttyUSB0 device using fopen using mode "w+". I need to both read and write from the device. I have set the port to raw mode (using tcgetattr, cfmakeraw, and tcsetattr). I use function fputc and fgetc to do my input and output a character at a time. I initially write to the port bytes. Then I receive bytes using fgetc. I can receive all the bytes I want, but once I try write again on usng fputc (which succeeds), then my call to fgetc return EOF and errorno says "Illegal Seek".
Does anyone know why doing a write to a serial port causes future reads to fail? It fails most of the time (sometimes it succeeds).