Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6843307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:13:45+00:00 2026-05-27T00:13:45+00:00

I’m writing an IO class to upload/download files to a controller over RS-232 serial.

  • 0

I’m writing an IO class to upload/download files to a controller over RS-232 serial. Unfortunately, I cannot send a whole file all at once, I have to break it into packets and send it a little bit at a time. Here’s the basic approach…

ifstream file ("path/to/file.ext", ios::in | ios::binary);

while( !file.eof() )
{
    //... zero buffer, and add packet header (8 bytes)
    size_t nResult = file.read( &buffer[8], 129 );
    Serial.Write( buffer, nResult+8 );
    //... see if controller wrote anything to the serial port and process it's command
    Sleep( 600 );
}

I know that using Sleep() is not a good design practice, but if I remove the Sleep() statement or even shorten the amount time the loop sleeps, then the controller throws errors about it’s buffer being full, and the transfer fails. Is there a better way to do this?

Before you say it, no I cannot send a message to the controller to determine if it’s ready for the next packet. It does not have that functionality.

Edit:
I forgot to mention that the interval at which I’m having to sleep is somewhat “blind.” The protocol specification provided by the manufacturer does not detail any length of time needed between packets. So I had to determine that value by trial and error. I’m afraid that it may not work on every PC and more so that it may not work on every controller.

This development is being done for Windows XP/Vista/7.

Edit #2:
Also, the amount of data per packet is actually a trial and error guess as well. The protocol specification allows for packets of 65,535 bytes (including the header). But if you send more than 129 bytes at a time, you start seeing issues where sometimes it works and sometimes it doesn’t. There also seems to be a relationship between the time you have to sleep and the amount of bytes you can send. If I drop the packet size down to 20 bytes per packet, I can drop the sleep time down to 400 milliseconds. I believe the reason for these issues stem from the time it takes to the controller to move data from its buffer to the file.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:13:46+00:00Added an answer on May 27, 2026 at 12:13 am

    What you are doing is called blind-cycle synchronization. It is not necessarily bad design. If your device does not have the functionality to indicate that it is ready for more data or not, this is the only way to do it.

    It is common for devices to specify a maximum data rate, or minimum amount of time between bytes.

    I think the idea of this being bad practice comes from cases where you blindly pick a delay value (performance will suffer if it is larger than it needs to be), if you have better synchronization methods available, or if you are using delays to cover up timing problems (say, in a multithreaded application).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.