我有一个通过串口发送的设备,在传输结束时它发送SUB / EOF(0x1A),但我不知道如何检查这些字符。这是我到目前为止所尝试过的。
private void sport_DataReceived(object sender, SerialDataReceivedEventArgs e)
string datareceived;
{
datereceived += sport.ReadExisting();
if (datareceived.Contains("\u001A"))
{
console.writeline(datareceived);
}
}
答案 0 :(得分:0)
我使用以下代码并获得了良好的效果。显然,EOF代表“文件结束”
private void sport_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
string datareceived;
datereceived += sport.ReadExisting();
if(e.EventType == SerialData.Eof)
{
console.writeline(datareceived);
}
}