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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:03:56+00:00 2026-05-30T23:03:56+00:00

Iam currently working on a project where i have to read serial port continuously.

  • 0

Iam currently working on a project where i have to read serial port continuously. The data is coming continuously for a max of 45 min. I have to validate the data via checksum and create a packet of 79 bytes. After this i have to plot the data(Trajectory) on a real time basis. The problem with the code is that at start it uses 20% of the CPU usage(Pentium 4, 3.0 GHz, Hyper threading)(which i think is still high) but with time the CPU usage increases and at end it reaches to 60%.

The data is coming in with a baud rate of 115200 and is sent continuously at the rate 100 msec.

My code for reading, validating and plotting is as follows:
The following function receive the data and validate it…

    private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
    {
        try
        {
            header1 = serialPort1.ReadByte();
            if (header1 == 0)
                header2 = serialPort1.ReadByte();
            if ((header1 == 0) && (header2 == 1))//Store the data in an array.
            {
                for (int i = 0; i < 77; i++)
                    abudata[i] = serialPort1.ReadByte();
                tail = abudata[76];
            }
            else
            {
                serialPort1.DiscardInBuffer();
            }
            checksum = 1;// Calculate the checksum.
            for (i = 0; i < 74; i++)
                checksum = checksum + (abudata[i]);
            checksum1 = (abudata[75] << 8);
            checksum1 = checksum1 + (abudata[74]);

            if ((checksum == checksum1) && (tail == 4))
                this.Invoke(new EventHandler(Display_Results));// Function to display
        }
        catch (Exception ode)
        {
            l4[4].BackColor = Color.Red;
        }
    }

The following function display the data on labels and draw the trajectory on a picture box

    private void Display_Results(object s, EventArgs e)
    {
        head1[0] = header1;
        head1[1] = header2;
        for (k = 0; k < 77; ++k)
            head1[k + 2] = (((int)abudata[k]) & 0x000000ff);
        jk = 0;
        for (k = 0; k < 36; ++k) //Data packing into 36 bytes
        {
            num_1[k] = (ulong)((head1[jk + 1]) + (head1[jk] << 8)) & 0x0000ffff;
            num_1[k] = (double)num_1[k];
            num_2[k] = (double)num_1[k];
            jk = jk + 2;
            signbit = (int)num_1[k] >> 15;

            if (signbit == 1)
            {
                sgnval = -1;
                num_1[k] = num_1[k] - 65535;
                num_1[k] = num_1[k] * (-1.0);
            }
            else
                sgnval = 1;

            //Converting the data into engineering values

            engval[k] = Math.Round(num_1[k] * parammaxval[k] * sgnval / 32767.0, 3);

            if (k == 14)
            {
                try
                {

                    curr_x = (pictureBox2.Width / 2) + (int)((engval[13] * (pictureBox2.Width)) / map_width);
                    curr_y = (pictureBox2.Height / 2) - (int)((engval[14] * (pictureBox2.Height)) / map_height);
                    PointF p1 = new Point(curr_x, curr_y);
                    if (_gPath != null && _gPath.PointCount > 0)
                        p1 = _gPath.PathPoints[_gPath.PathPoints.Length - 1];
                    PointF p2 = new Point(curr_x, curr_y);
                    _gPath.AddLine(p1, p2);
                    pictureBox2.Invalidate();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

        }           
    }    
  • 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-30T23:03:57+00:00Added an answer on May 30, 2026 at 11:03 pm

    i got what was the problem with the above code..

    I am using Graph path for plotting the trajectory

    if (k == 14)
    {
        try
        {
    
            curr_x = (pictureBox2.Width / 2) + (int)((engval[13] * (pictureBox2.Width)) / map_width);
            curr_y = (pictureBox2.Height / 2) - (int)((engval[14] * (pictureBox2.Height)) / map_height);
            PointF p1 = new Point(curr_x, curr_y);
            if (_gPath != null && _gPath.PointCount > 0)
                p1 = _gPath.PathPoints[_gPath.PathPoints.Length - 1];
            PointF p2 = new Point(curr_x, curr_y);
            _gPath.AddLine(p1, p2);
            pictureBox2.Invalidate();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }
    

    Now as the application continues to run, it gathers lots of graph points and hence plotting this huge number of point is consuming the resources.

    Can anybody suggest me solution to this problem that how to plot the trajectory without slowing the system…

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

Sidebar

Related Questions

I am currently working on a project where I have to read a text
Hi Currently i am working on a rails project . where i have to
I am currently working on a project where I a data matching algorithm needs
i would like to have your opinion in a project i am currently working
I am currently working on a spring portlet mvc 3 project. I have a
I am currently working on a MVC3 project with Razor. I have switchen on
I am currently working on a C# wpf project. I have a listbox and
I am currently working on a C# project where I have a list initialised
I am currently working on a windows phone project where i have test the
I have a project I am currently working on that has multiple validators and

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.