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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:48:41+00:00 2026-06-10T11:48:41+00:00

In my handler for receiving data over the serial port, when data is received

  • 0

In my handler for receiving data over the serial port, when data is received I store it to a string and do a .contains search to determine if something needs to be done with the data. When the application is sitting idle and the (lets call it a modem) sends something like “Connected” it works fine.

The problem is when I poll the machine. When I initiate a command that expects return results It does not work and I cant figure out why. Now If I start the function with a Message Box it will work. I would rather not have an unnecessary Message Box.

Here is a sample of my code.

private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
    if (this.InvokeRequired)
    {
        RefreshTextBox d = new RefreshTextBox(RefreshTextBoxResults);
        Invoke(d);
    }
    else
    {
        RefreshTextBoxResults();
    }
}

private void RefreshTextBoxResults()
{
    //MessageBox.Show("refresh text is occurring");
    indata1 = serialPort1.ReadExisting();
    rx.AppendText(indata1);

    string dataCheck = indata1.ToUpper();

    //MessageBox.Show(dataCheck);
    if (indata1.ToUpper().Contains("CONNECT"))//dataCheck.Contains("CONNECT"))
    {
        // MessageBox.Show("connect");
        cState.Text = "Connected";
        if(connected==false)
            connectLink();
    }
    if (dataCheck.Contains("CONNECTED"))
    {
        // MessageBox.Show("Active Call in Session");
        cState.Text = "Connected";
        if (connected==false)
            connectLink();
    }
    if (dataCheck.Contains("NO"))
    {
        cState.Text = "Disconnected";
        disconnect();
    }
    if (dataCheck.Contains("CAMPOS"))
    {
        campos = indata1;
        camDat = true;
    }
}

private void cState_Click(object sender, EventArgs e)
{
    writeDevice("callstatus");
}

public void writeDevice(string cmd)
{
    try
    {
        {
            serialPort1.Write(cmd + "\r\n");
        }
    }
    catch
    { noconnect(); }
}

When I execute cstate() it should return the call status and type if any. The modem does respond as I can see it in my prompt box. If the word connected is anywhere in there It should change a label’s text to say “Connected”. As the code sits, nothing happens to that label. But, if I remove the comment on the first line in RefreshTextBoxResults() making that MessageBox active, it detects the status of the modem.

I just don’t see what is going on. Can someone explain to me why this is happening?

  • 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-10T11:48:42+00:00Added an answer on June 10, 2026 at 11:48 am

    But, if I remove the comment on the first line in RefreshTextBoxResults()

    That’s the key phrase. The issue is that you use ReadExisting(). Serial ports are very slow, your DataReceived event handler will typically only get one or two characters. By displaying the message box, you slow it down. That allows the serial port driver to read more characters. Enough for ReadExisting to read the entire “Connected” string instead of just “C” or “Co”.

    Hard to diagnose too when you use a debugger, single stepping the code also slows it down enough to allow the port to get enough characters.

    What you need to do is process the response only after you got the entire response string. That’s always easy with a modem, just use ReadLine() instead of ReadExisting(). You may have to tweak the value of the NewLine property.

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

Sidebar

Related Questions

I am receiving data from a device that's sending information over the serial port
I have a service which contains a Timer and TimerTask for receiving data from
I have a service which contains a Timer and TimerTask for receiving data from
I have an App that has a thread handler receiving some socket data all
I am working on a small project that is receiving XML data in string
My app is receiving data from a BlueTooth device 4 times a second, parsing
I have a situation where my website needs to quickly retrieve data from my
My application is unable to transfer data properly over a socket connection and write
I'm building this tool for classifying data. Basically I will be regularly receiving rows
I am receiving a EM_CHARFORMAT message in my message handler when SetFont() is called

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.