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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:26:40+00:00 2026-06-06T09:26:40+00:00

Visual Studio 2010 C# code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using

  • 0

Visual Studio 2010 C# code:

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;

namespace YamanPonics
{
    public partial class Form1 : Form
    {
        string RxString;

        //Default SerialPortStatus equals TRUE when first starting up
        Boolean serialPortDisconnected = true;

        public Form1()
        {
            InitializeComponent();

            //Add available Serial COM ports to combobox
            foreach (string ports in System.IO.Ports.SerialPort.GetPortNames())
            {
                //MessageBox.Show("Serial port avialible" + " " + ports);
                comPortCmbBox.Items.Add(ports);
            }
        }

        private void DisplayText(object sender, EventArgs e)
        {
            serialMsgViewerRchTxt.AppendText(RxString);
            MessageBox.Show("Displayed Serial Text!");
        }

        private void serialPort1_DataReceived (object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {   
            RxString = serialPort1.ReadExisting();
            this.Invoke(new EventHandler(DisplayText));
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            //If SerialPort1 IsOpen
            if (serialPort1.IsOpen)
            {
                //Close SerialPort1 communication
                serialPort1.Close();
            }
        }


        private void connectDisconnectBtn_Click(object sender, EventArgs e)
        {
            //Set arduinoComPort value to COM Port value
            string arduinoComPort = comPortCmbBox.Text;

            //if SerialPortStatus boolean equals FALSE then
            if (serialPortDisconnected &&  (arduinoComPort != ""))
            {

                //Set serialPort1 BaudRate value to default value of 38400(required for atlas-scientific sensors)
                serialPort1.BaudRate = 38400;

                //Set serialPort1 Read and Write timeout values
                serialPort1.ReadTimeout = 250;
                serialPort1.WriteTimeout = 250;

                //Set serialPort1 DataBits value
                serialPort1.DataBits = 8;

                //Open serialPort1 communication
                serialPort1.Open();

                //Change connectDisconnectBtn text to Disconnect
                connectDisconnectBtn.Text = "Disconnect";

                //Set serialPortDisconnected to FALSE
                serialPortDisconnected = false;

            }
            else //if SerialPortStatus bollean equals TRUE
            {
                //Close SerialPort1 communication
                serialPort1.Close();

                //Set connectDisconnectBtn text to Connect
                connectDisconnectBtn.Text = "Connect";

                //Set serialPortDisconnected to TRUE
                serialPortDisconnected = true;
            }
        }

        private void SendBtn_Click(object sender, EventArgs e)
        {
            //if serialPort1 IsOpen then
            if (serialPort1.IsOpen)
            {
                serialPort1.Write("{ph}");
            }
        }
    }
}

That code is a simple Serial connect/disconnect and send/receive application. Connect, Disconnect, and send works properly. When my arduino receives a command it sends a response back. My 2010 C# application is not receiving the response in the richtextbox and do not understand why. I can receive a response when I use another serial terminal program so I do know for sure that data is being sent. What am I not doing to successfully receive a response?

  • 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-06-06T09:26:41+00:00Added an answer on June 6, 2026 at 9:26 am

    Are you sure the serialPort1.DataReceived event is wired up correctly? I see you have the handler method, but I don’t see you subscribing to the event.

    You need to have this somewhere:

    serialPort1.DataReceived += serialPort1_DataReceived;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code below is in C# and I'm using Visual Studio 2010. using System;
I am using visual studio 2010 and Oracle 10g. Operating system: Windows 7 home
When I generate code using T4 templates in Visual Studio 2010, I get the
I want to be able to develop code using Visual Studio 2010. I just
I have a asp.net website with c# code behind and using visual studio 2010.
I am writing Python code in Visual Studio 2010 using the excellent Python Tools
I am using an addon called Code Map in Visual Studio 2010 which makes
I wrote this simple C code and compiled it using Visual Studio 2010, with
Sometimes, when I'm ckeckin out source code using Microsoft Visual Studio Team System 2008
I am using Visual Studio 2010 Professional Edition, and Windows Vista. Firstly, I have

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.