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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…