private void Form1_Load(object sender, EventArgs e)
{
serialPort1.PortName = "COM1";
serialPort1.BaudRate = 9600;
serialPort1.Parity = Parity.None;
serialPort1.DataBits = 8;
serialPort1.StopBits = StopBits.One;
serialPort1.Open();
serialPort1.ReceivedBytesThreshold = 1;
serialPort1.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);
}
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
this.label1.Text =serialPort1.ReadLine();
}
private void button1_Click(object sender, EventArgs e)
{
if (serialPort1.IsOpen)
{
label1.Text = "打开";
}
else
{
label1.Text = "guanbi";
}
}
private void serialPort1_PinChanged(object sender, SerialPinChangedEventArgs e)
{
}
}
}