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个,怎么改呢?
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"); }