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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:54:34+00:00 2026-05-31T02:54:34+00:00

i have a problem. i try to listen serial port(COM20), and then i receive

  • 0

i have a problem. i try to listen serial port(COM20), and then i receive data, i want add this data to ListBox1 on application form. What code i need to add for it?
i know about INVOKE, but i dont understand how i must use it. Help me please.

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

namespace test_com_port
{
    public partial class Form1 : Form
    {


        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SerialPort mySerialPort = new SerialPort("COM20");
            mySerialPort.BaudRate = 9600;
            mySerialPort.Parity = Parity.None;
            mySerialPort.StopBits = StopBits.One;
            mySerialPort.DataBits = 8;
            mySerialPort.Handshake = Handshake.None;



            mySerialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
            mySerialPort.Open();

        }
        private static void DataReceivedHandler(object sender,SerialDataReceivedEventArgs e)
        {
          SerialPort sp = (SerialPort)sender;
                string indata = sp.ReadExisting();


        char[] values = indata.ToCharArray();
        foreach (char letter in values)
        {

            int value = Convert.ToInt32(letter);
            string hexOutput = String.Format("{0:X}", value);
            listBox1.Items.Add(hexOutput);


        }  

        }

    }


    }
  • 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-31T02:54:36+00:00Added an answer on May 31, 2026 at 2:54 am

    Just add add the top of your event handler:

    if (InvokeRequired)
     BeginInvoke(new SerialDataReceivedEventHandler(DataReceivedHandler), sender, e);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem when try to use hashtable with large data. I have
I have this problem when i try to synchronize a observable list with listbox/view
i am having this problem try to use the cocos2d CCScrollLayer I have added
i have the problem when i want to try web socket technology on my
I have a problem, when I try to record and then play the file
I have an application where i need to write some data to the serial
I have the following code to listen firefox quit-application event observe: function(subject, topic, data)
i have an application which listen on sockets. this application is monitored by nagios.
i have a problem when try to get and parse a remote JSON. require
I have a problem when I try to count how many times a word

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.