private void button1_Click(object sender, EventArgs e) { serialPort1.Open(); serialPort1.DataReceived += new SerialDataReceivedEventHandler(sp5_DataReceived); serialPort1.Write(cmdByte, 0, 8); } void sp5_DataReceived(object sender, SerialDataReceivedEventArgs e) { Thread.Sleep(500); System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false; SerialPort port = (SerialPort)sender; byte[] buf = new byte[50]; int len = port.Read(buf, 0, buf.Length); MessageBox.Show(len.ToString()); serialPort1.DataReceived -= new SerialDataReceivedEventHandler(sp5_DataReceived); port.Close(); }