Sign in to follow this  
Floating

Some easy questions about serial port...

Recommended Posts

Floating    122
Hi, I have been using serial ports since some time and it worked fine most of the time. Sometimes it behaves a little bit strange to my eyes and I realized that I don't know how it is working exactly. If I write something to serial port, is it like a tube where on one side you enter data and on the other side you read data? Data won't get erased in the tube right? (unless maybe a maximum buffer is reached). Now when I wait for a receive event, and then I read data, will I read everything that was sent? Or only the beginning? (if my computer is very fast) For example: on computer 1: write("abcdefghijklmnop") on computer 2: wait for receive event read data Will data contain "abcdefghijklmnop" or can it sometimes only contain "abcdef" for instance? (maybe the receive event was triggered before all that data had time to arrive) Sounds maybe silly to you, but I sometimes get only one char instead of the whole string. Thanks for your help :)

Share this post


Link to post
Share on other sites
fractoid    703
Depending on the API used to access the serial port, you should have some way to set a timeout. So, for instance, if your transmitting device/application sends "abcde" and then "fghomg" 200 milliseconds later, then as long as your timeout on the receiving end is set more than 200 milliseconds plus baudrate / (8 * strlen("abcdefghomg"))), you will receive the whole thing as a single string. This can actually be annoying - if your receiving end is slow or has a long timeout you may end up with separate transmittions being coalesced.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this