José González José González - 1 month ago 10
C# Question

How can I check for the characters SUB/EOF(0x1A) in a serial communication?

I have a device which sends trough a serial port, at the end of the transmission it sends SUB/EOF(0x1A), but I´m not sure how to check for those characters. This is what I've tried so far.

private void sport_DataReceived(object sender, SerialDataReceivedEventArgs e)


string datareceived;
{

datereceived += sport.ReadExisting();
if (datareceived.Contains("\u001A"))
{
console.writeline(datareceived);
}

}

Answer

I used the following code with good results. Apparently EOF stands for "End of file"

private void sport_DataReceived(object sender, SerialDataReceivedEventArgs e)  

{
string datareceived;
datereceived += sport.ReadExisting();

if(e.EventType == SerialData.Eof)
{
console.writeline(datareceived);
}
}