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

  • Home
  • SEARCH
  • 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 6192781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:00:13+00:00 2026-05-24T03:00:13+00:00

I have a project in which I am expected to read data from a

  • 0

I have a project in which I am expected to read data from a scale using rs232. The output from the scale is in the format “L00000”.My problem is that the scale sends data continuously as it weighs like “L00000,L00001,L00002,L00003,L00004”. My interest in this case is to obtain the last part “L00004” to be stored in the db.
Here is my code: Kindly help me improve it. Thanks

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;

namespace WindowsFormsApplication5
 {
public partial class Form1 : Form
{
    private List<byte> PortBuffer = new List<byte>();
    SerialPort comPort = new SerialPort("COM3", 9600, Parity.None, 8, StopBits.One);
    public Form1()
    {
        InitializeComponent();

    }

    private void button1_Click(object sender, EventArgs e)
    {


        if (comPort.IsOpen)
        {
            comPort.DiscardOutBuffer();
            MessageBox.Show("Data cleared");
            comPort.Close();
        }

        if(!comPort.IsOpen)
        {
        comPort.Open();
        //sample of data as written by the scale. How can I get the last chunk only so that I format it for my needs
        comPort.Write("L00002 L00002 L00002");

        int bytes = comPort.BytesToRead;
        byte[] buffer = new byte[bytes];
        comPort.Read(buffer, 0, buffer.Length);

        comPort.DataReceived += new SerialDataReceivedEventHandler(data_received);

        comPort.Close();
       }
       }
    public void data_received(object sender,SerialDataReceivedEventArgs e)
    {
        MessageBox.Show("test" + comPort.ReadExisting().ToString());

    }

   }
 }
  • 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-24T03:00:17+00:00Added an answer on May 24, 2026 at 3:00 am

    How is the data seperated, is the a space a , or no seperation?

    If its a , like in the question then

    var data=comPort.ReadExisting().ToString();
    var result=data.Split(',').Last();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Silverlight Project which passes data using the Data Contract to a
I have a project which is source controlled using Subversion and VisualSVN. Since the
I have a .NET project which references another assembly that is built outside of
I have this C++ project which compiles using a Makefile, and sometimes when (
I have a project which I have copied from my old workspace to a
I have an iOS project which builds and executes as expected under debug yet
On a current project which I'm currently working, i have a symfony task that
I have C++ project (VS2005) which includes header file with version number in #define
I have a Rails project which I neglected to build tests for (for shame!)
I have a Rails project which has a Postgres database for the actual application

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.