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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:04:29+00:00 2026-05-27T09:04:29+00:00

I have a wrapper class that wraps .Net’s SerialPort class to perform modem operations

  • 0

I have a wrapper class that wraps .Net’s SerialPort class to perform modem operations and data flow. When I’m reading from the SerialPort object, the data that I previously wrote to the port is found within the receive buffer. Is that a behavior that I can change with the SerialPort object? I haven’t found a property for the class that prevents my outgoing data from ending up in the receive buffer.

I use SerialPort.Write() to write the data and this is what I do to read data

private void SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
    Task.Factory.Startnew(() => WriteToBuffer());
}

// ... 

private void WriteToBuffer()
{
    string data = string.Empty;

    lock(_serialPort)
    {
        StringBuilder sb = new StringBuilder();

        while(_serialPort.BytesToRead > 0)
        {
            sb.Append(_serialPort.ReadExisting());
        }

        data = sb.ToString();
    }

    // .. then do some additional processing
}

I read the data in a non-blocking manner because I’d rather be paranoid and not miss any data received events and have client code think there was some type of timeout.

I can prevent Hayes AT commands from being copied into the receive buffer by sending ATE0 but any data I send after the modem is connected to a remote modem is still creeping into the receive buffer.

Is there anything I can do? It’s hard to just check and see what I wrote last to the buffer and ignore it because sometimes I read one byte at a time and is part of the data returned. For instance if I send something like “ID 123”, I might read “ID ” with the while loop and find that there are 0 bytes to read so it stops there. I know that I could just call a Thread.Sleep() each time but I think that would not be good practice.

Can I expect this echoing behavior in ALL modems? If so, then I can add code to filter my written data.

  • 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-27T09:04:29+00:00Added an answer on May 27, 2026 at 9:04 am

    I tried out a handful of other modems and the write data returned in the input buffer just like the original modem model that I tried. My solution was to filter out the written data to correctly read other data coming from the remote modem.

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

Sidebar

Related Questions

I have a class 'Database' that works as a wrapper for ADO.net. For instance,
This may be familiar to some. I have a wrapper class Ex that wraps
I have a wrapper generic class that intended to be used with a set
I have a class (see example bellow) which acts as a .NET wrapper for
I have a View with a form which displays data from objects that are
I have a object that wraps all access to SQLAlchemy, let's called it Wrapper.
I have a class method that returns a pointer to an inner data structure
I have a working wrapper class for Dallmeier camera devices, It contains a callback
I have a class written in c# which is acting as a wrapper around
I have a wrapper around a C++ function call which I call from C#

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.