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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:37:00+00:00 2026-06-14T22:37:00+00:00

In my SerialPort.DataReceived event handler, I am checking for SerialData.Eof : void DataReceived(object sender,

  • 0

In my SerialPort.DataReceived event handler, I am checking for SerialData.Eof:

void DataReceived(object sender, SerialDataReceivedEventArgs e) {
    if (e.EventType == SerialData.Eof)
        throw new NotImplementedException("SerialData.Eof");
    // ... Read
}

In my entire development up to this point, I have never hit this exception. But today, when working on a different piece of the protocol, it hit.

My question is, what exactly does SerialData.Eof mean? MSDN says:

The end of file character was received and placed in the input buffer.

I’m dealing with binary data. What is the “end of file character”?


This MSDN Forum Post states that

the DCB.EofChar member always gets initialized to 0x1A (Ctrl+Z)

In the reference sources for the SerialStream class, at line 1343, we see that indeed:

dcb.EofChar = NativeMethods.EOFCHAR;

And in Microsoft.Win32.NativeMethods:

internal const byte EOFCHAR = (byte) 26; 

So does this mean anytime my device sends an 0x1A byte, that I will get a SerialData.Eof event? If that is the case, should I just stop testing for it altogether?

  • 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-14T22:37:01+00:00Added an answer on June 14, 2026 at 10:37 pm

    My original analysis in that MSDN post was correct. However, the reference source reveals the answer, from SerialStream.cs:

    dcb.EofChar = NativeMethods.EOFCHAR;
    
    //OLD MSCOMM: dcb.EvtChar = (byte) 0;
    // now changed to make use of RXFlag WaitCommEvent event => Eof WaitForCommEvent event
    dcb.EvtChar = NativeMethods.EOFCHAR;
    

    Ugh, they used the DCB’s EvtChar setting to detect a Ctrl+Z. This was a Really Bad Idea, given that there’s no way to change it and a 0x1a byte value can certainly appear in a binary protocol. In practice this almost always comes to a good end since there will be something to read when the event fires. Nevertheless, there’s now a race condition that can fire another event, this time SerialData.Chars, with nothing to read since the previous event caused all bytes to be read. Which will make the Read() call block until a byte is available. Which usually works out but does increase the odds that the Close() call deadlocks. A chronic SerialPort problem.

    The proper way to deal with this is:

    void DataReceived(object sender, SerialDataReceivedEventArgs e) {
        if (e.EventType == SerialData.Eof) return;
        // ... Read
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My problem: I have DataReceived event for SerialPort, which listens to serial port and
I have an open SerialPort and receive data through the DataReceived event. Is there
Relates to the problem Adding event handler in main() for SerialPort After I change
I'm reading data from a serial port, but the DataReceived event of SerialPort is
I have a module with an event for serial port signal serialPort.DataReceived.AddHandler(SerialDataReceivedEventHandler(DataReceived)); where DataReceived
In .Net's SerialPort object, is there a way to determine if a serial port
I'm using the SerialDataReceivedEventHandler to know when my SerialPort object receives data. Is it
I'm reading data from a serial port using an event listener from the SerialPort
I am working on a serial port related application. While using DataReceived event of
I am working on a serial port related application. While using DataReceived event of

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.