I'm writing a simple script to get data from temperature sensors on rs232. It's query-answer based so I first need to send the query in the right form and subsequently read/parse the answer. Additional sync query before the actual one is needed.

How can I correctly flush the read buffer so I only get the last answer and not everything that was received from sensors? I tried with lookclear but that doesn't help me. The $answer ends up having data received after all three queries (writes).