如何在串行通信中检查字符SUB / EOF(0x1A)?

时间:2016-04-02 18:07:06

标签: c# unicode serial-port

我有一个通过串口发送的设备,在传输结束时它发送SUB / EOF(0x1A),但我不知道如何检查这些字符。这是我到目前为止所尝试过的。

private void sport_DataReceived(object sender, SerialDataReceivedEventArgs e)  


string datareceived;
{

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

}

1 个答案:

答案 0 :(得分:0)

我使用以下代码并获得了良好的效果。显然,EOF代表“文件结束”

private void sport_DataReceived(object sender, SerialDataReceivedEventArgs e)  

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

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