似乎无法在这里找到我一生的答案。无论如何,事件处理程序如何更改 Form 的 textBox.text?
private static void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
string indata = sp.ReadExisting();
//Do what ever you want with the data
textBox2.Text = "test"; //alas, this doesn't work
}
按下按钮时创建事件处理程序
private void button3_Click(object sender, EventArgs e)
{
serialPort1.PortName = comboBox1.Text;
serialPort1.BaudRate = Convert.ToInt32(comboBox2.Text);
serialPort1.RtsEnable = true;
serialPort1.DtrEnable = true;
serialPort1.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
serialPort1.Open();
}
}
任何帮助是极大的赞赏
慕雪6442864
SMILET
相关分类