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 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 two project, one which generates some artifacts from a WSDL file using
I have a project which is source controlled using Subversion and VisualSVN. Since the
I have a project which contains different components that everyone works on. We have
I have a project which builds correctly from the command line. On one of
I have an iOS project which builds and executes as expected under debug yet
I have a shared library project that is built from 4 static libraries (
I am developing an application using WPF/MVVM. I have a WCF data service project
I'm currently working on a large project which is expected to have a large
I have a maven project which won't compile due to an unresolvable reference from
I have a project which it's domain contain following classes: Courier Customer Food Order

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.