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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:26:34+00:00 2026-05-13T20:26:34+00:00

I made an application in C# which sends 11 byte of data to a

  • 0

I made an application in C# which sends 11 byte of data to a serial port using:

            port = new SerialPort("COM1");
            port.BaudRate = 9600;
            port.DataBits = 8;
            port.Parity = Parity.None;
            port.StopBits = StopBits.One;
            port.ReadTimeout = 1000;
            port.WriteTimeout = 1000;
            port.Open();

            byte[] buffer = new byte[11];
            buffer[0] = 0;
            buffer[1] = 0;
            buffer[2] = 0;
            buffer[3] = 3;
            buffer[4] = 2;
            buffer[5] = 4;
            buffer[6] = 1;
            buffer[7] = 20;
            buffer[8] = 50;
            buffer[9] = 0;
            buffer[10] = 120;
            port.Write(buffer, 0, 11);

Then I wrote another application to test the previous one. I would like to check if the 11 bytes were correctly sent. In this application I use:

        using (SerialPort port = new SerialPort("COM1"))
        {
            // configure serial port
            port.BaudRate = 9600;
            port.DataBits = 8;
            port.Parity = Parity.None;
            port.StopBits = StopBits.One;
            port.Open();

            for (; ; )
            {
                byte[] b = new byte[11];
                port.Read(b, 0, 11);
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < 11; ++i)
                {
                    sb.Append(b[i]);
                    sb.Append(" ");
                }
                Console.WriteLine(sb.ToString());
            }
        }

to receive bytes. The problem is that, after sending something like this:

0 0 0 3 2 4 1 20 50 0 120

I receive:

0 0 0 0 0 0 0 0 0 0 0
0 0 3 2 1 4 20 50 0 120 0

Why does it happen? What kind of error is there in my code?
Thank you

  • 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-13T20:26:34+00:00Added an answer on May 13, 2026 at 8:26 pm

    You’re not checking the result from port.Read(). It returns the number of bytes read, not the number of bytes requested. The output loop then needs to use this result as the upper limit.

    Although you’ve setup timeouts on the sending side, you’ll also need them on the reader too.

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

Sidebar

Related Questions

I made textbox, but it needs to send data to other application, which have
We have already shipped a client (.NET WinForms) application which sends customer data to
I have successfully made an facebook application which shows real time data from facebook
I have made a sample application which constructs a filter graph to capture audio
I've been given a Flex application which made use of a RESTFUL service. I've
I'm in the process of creating a C# application which will monitor changes made
i have a windows application made in VB.NET which maintains a database, and i
I have an application in which we use a hand-made build system.The reason for
I have made a swings application but there is one problem in that which
I'm about to start on a large Qt application, which is made up of

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.