首页 新闻 搜索 专区 学院

c#调用Comm_DataReceived的数据问题?

0
[已解决问题] 解决于 2017-06-13 21:56

private void Comm_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
int n = comm.BytesToRead;
buf = new byte[n];
comm.Read(buf, 0, n);
builder.Clear();
this.Invoke((EventHandler)(delegate
{
builder.Append(Encoding.ASCII.GetString(buf));
buffer = (Encoding.ASCII.GetString(buf)).ToString();
this.textBox1.AppendText(builder.ToString());
}));
}
private void button_send_Click(object sender, EventArgs e)
{
comm.Write(textBox_write.Text + "\r\n");
}
private void button1_Click(object sender, EventArgs e)
{
if (buffer.Contains("a"))
{
MessageBox.Show(buffer);
}
}
我点击send发送指令后,在点击 button1,这时候可显示buffer,
现在我想把2个button合并为1个,怎么改呢?

addsds的主页 addsds | 菜鸟二级 | 园豆:226
提问于:2017-06-13 13:20
< >
分享
最佳答案
0
private void Comm_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
int n = comm.BytesToRead;
buf = new byte[n];
comm.Read(buf, 0, n);
builder.Clear();
this.Invoke((EventHandler)(delegate
{
builder.Append(Encoding.ASCII.GetString(buf));
buffer = (Encoding.ASCII.GetString(buf)).ToString();
this.textBox1.AppendText(builder.ToString());
if (buffer.Contains("a"))
{
MessageBox.Show(buffer);
}
}));
}
private void button_send_Click(object sender, EventArgs e)
{
comm.Write(textBox_write.Text + "\r\n");
}
奖励园豆:5
hahanonym | 小虾三级 |园豆:1460 | 2017-06-13 17:14
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册