private void SetServer_Load(object sender, EventArgs e)
{
comport.BaudRate = 9600;
comport.DataBits = 8;
comport.StopBits = (StopBits)Enum.Parse(typeof(StopBits), "One");
comport.Parity = (Parity)Enum.Parse(typeof(Parity), "None");
comport.Encoding = Encoding.GetEncoding("GBK");
comport.PortName = "COM1";
comport.Open();
comport.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
}
private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
try
{
data = comport.ReadExisting();
this.textBox1.Invoke(new EventHandler(delegate
{
this.textBox1.Text =this.textBox1.Text+ data;
}));
//this.textBox1.Text = data;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}