Search code examples
clinuxserial-portmodem

totally clear a modem module serial buffer during reading


I have a gsm modem module, first of all I tried it from microcom appl. and everything was fine. Secondly I implemented my own code in c. If I pass the AT commands I can read that and its answer many times. How I can clear the port? It seems sometimes I can read the port almost until forever. :-)

I tried not to consider that, but it causes confusion when I process the responses.

I use Linux.

Tamas


Solution

  • You can use tcflush() to flush the input, output, or both.

    tcflush() discards data written to the object referred to by fd but not transmitted, or data received but not read, depending on the value of queue_selector:

       TCIFLUSH
              flushes data received but not read.
    
       TCOFLUSH
              flushes data written but not transmitted.
    
       TCIOFLUSH
              flushes both data received but not read, and data written but not
              transmitted.