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 8026511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:31:00+00:00 2026-06-04T23:31:00+00:00

I am interfacing a scale to a computer through a serial port. I check

  • 0

I am interfacing a scale to a computer through a serial port. I check the value SerialPort.BytesToRead for when it reaches 0 inside a loop. However the loop exits even though BytesToRead is not equal to 0. I can’t post a screenshot as I am a new user but by going through debug I can see that BytesToRead is in fact not 0.

This results in my data not being read entirely. I have tried for different expressions such as _port.BytesToRead > 0 but the result is the same. Even assigning the value of BytesToRead to a variable gives a 0. Without the loop ReadExisting doesn’t return all the data sent from the scale so I don’t really have a choice. ReadLine doesn’t work either. So why is BytesToRead always 0?

private void PortDataReceived(object sender, SerialDataReceivedEventArgs e)
    {
        {
            var input = string.Empty;
            // Reads the data one by one until it reaches the end
            do
            {
                input += _port.ReadExisting();
            } while (_port.BytesToRead != 0);

            _scaleConfig = GenerateConfig(input);

            if (ObjectReceived != null)
                ObjectReceived(this, _scaleConfig);
        }
    }
  • 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-06-04T23:31:02+00:00Added an answer on June 4, 2026 at 11:31 pm

    My boss figured it out. Here’s the code.

    private void PortDataReceived2(object sender, SerialDataReceivedEventArgs e)
        {
            var bytesToRead = _port.BytesToRead;
            _portDataReceived.Append(_port.ReadExisting());
    
            // Buffer wasn't full. We are at the end of the transmission.
            if (bytesToRead < _port.DataBits)
            {
                //Console.WriteLine(string.Format("Final Data received: {0}", _portDataReceived));
                IScalePropertiesBuilder scaleReading = null;
    
                scaleReading = GenerateConfig(_portDataReceived.ToString());
                _portDataReceived.Clear();
    
    
                if (ObjectReceived != null)
                {
                    ObjectReceived(this, scaleReading);
                }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am interfacing with a USB-to-serial port that can be inserted or removed at
If we check the official documentation we can find various ways of interfacing Erlang
Any idea on interfacing with AutoCAD through a JAVA program. I am looking for
I'm interfacing scala to some native code (through java+jna) and am about to rewrite
I am interfacing with a server that requires that data sent to it is
I'm interfacing to a WCF web service that exposes its method using SOAP, using
In our current project we are interfacing with a third party data provider. They
So I've been looking at interfacing with xml files for a project I've been
I have a 3rd party library i am interfacing with using a facade pattern.
I'm in the process of working on interfacing a haptic robot and eye tracker.

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.