Jump to content

How does exactly work the "flush" function on the Serial port?


Recommended Posts

Posted

Hi everybody,

I'm working with the serial communication port and even though I'm flushing both the buffers (either the receiver and the transmitter) when I go to read the answer to the command I've already sent on the bus I also read the echo of the command. The flush functions are set before the reading procedure then I guessed this functions cleans both the buffers on the serial device but it doesn't do it. So, can anyone explain to me how exactly work the flush function on the serial port?

Thank you in advance.

Posted

Serial devices can be quite slow, so you have probably flushed the buffers long before the device sends back its response (including the echoed command).

Since you know what the command string was, you can easily strip it off the front of the response.

Posted

I always flush the buffer, read 10000 chars with 1ms timeout and then send my command. I also make sure that my target is not set to echo the command. (or if it does, I deal with it explicitly).

This has worked well for me in a large system with 100s of ports for many years.

  • Like 2

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.