Jump to content
  • Advertisement
Sign in to follow this  
Floating

Some easy questions about serial port...

This topic is 4960 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
you will only get as much infomation as is in the buffer at the time of reading, so if the computer is fast enuff it could read the buffer before all the data is in.

Share this post


Link to post
Share on other sites
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!