I have a serial device on /dev/ttyAMA0. I have program written in C that communicates with this device. But apart from the C program I sometimes need to input some configuration data from terminal, for example: echo xxx >> /dev/ttyAMA0. Problem is that the device replies to this configuration input (something like parameter xxx set) but I do not read (because I don't need to) this reply so it buffers in the serial port's buffer. This causes problems in the C program because I need to read data from it but there is already this reply buffered that I do not care about.

So my question. How do I flush device's buffer from terminal? I know I can use tcflush(sfd, TCIOFLUSH); in C but I need to do it from terminal.

  • You are asking the wrong question. The right question to ask is what tool you can use to speak with your device properly, since echo clearly only does half the job. – JdeBP Feb 25 '19 at 10:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.