c#DataReceived收到的数据包不完全
privatevoidComport_DataReceived(objectsender,SerialDataReceivedEventArgse){intn=compo...
private void Comport_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
int n = comport.BytesToRead;
byte[] buf = new byte[n];
comport.Read(buf, 0, n);
builder.Clear();
this.Invoke((EventHandler)(delegate
{
builder.Append(Encoding.ASCII.GetString(buf));
buffer = (Encoding.ASCII.GetString(buf)).ToString();
Fixture2_message.AppendText(builder.ToString());
if (buffer.Contains("{{(rxPacket)}"))
{
count++;//为全部变量
Fixture1_message.AppendText(count.ToString() + ",");
}
}));
}
当发指令后,DataReceived理论会收到100个包,但是现在我这样写代码,只收到98个,不知道出错在哪里,请帮忙看看。 展开
{
int n = comport.BytesToRead;
byte[] buf = new byte[n];
comport.Read(buf, 0, n);
builder.Clear();
this.Invoke((EventHandler)(delegate
{
builder.Append(Encoding.ASCII.GetString(buf));
buffer = (Encoding.ASCII.GetString(buf)).ToString();
Fixture2_message.AppendText(builder.ToString());
if (buffer.Contains("{{(rxPacket)}"))
{
count++;//为全部变量
Fixture1_message.AppendText(count.ToString() + ",");
}
}));
}
当发指令后,DataReceived理论会收到100个包,但是现在我这样写代码,只收到98个,不知道出错在哪里,请帮忙看看。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询