如何在richTextBox中显示从串口接收到的数据啊? 用SerialPort类监视串口,并接收数据,然后把它在richTextBox中显示SerialPort类的用法很简单,狗狗或者msdn 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 System.IO.Ports.SerialPort port = new System.IO.Ports.SerialPort("COM5");//定义串口 private void Form1_Load(object sender, EventArgs e) { port.BaudRate = 19200; port.Open(); port.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(port_DataReceived);//设置响应事件 RichTextBox.CheckForIllegalCrossThreadCalls = false;//运行子线程修改RichTextBox的内容 } void port_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) { int bytesToRead = port.BytesToRead; if (bytesToRead > 0) { char[] c = new char[bytesToRead]; port.Read(c, 0, bytesToRead); richTextBox1.Text += new string(c);//显示串口出来的数据 } } 关于。NET窗体应用程序开发,不知道为什么不能运行 聊天代码问题 本人想实现定时发邮件,现求怎样才能激活发邮件的代码,请各位大虾帮忙! 关于常数定义...... C#中调用Excel的问题:接口 Excel._Application 的 QueryInterface 失败。 谁有看到开心小闹钟的源代码呢 用winform些一个收邮件的程序! 如何在线程中操纵窗口对象 请问!c#能和pb混合编程吗? 返回dataset用什么? C#注册表操作问题 初学c#的困惑
{
port.BaudRate = 19200;
port.Open();
port.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(port_DataReceived);//设置响应事件
RichTextBox.CheckForIllegalCrossThreadCalls = false;//运行子线程修改RichTextBox的内容
} void port_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
int bytesToRead = port.BytesToRead;
if (bytesToRead > 0)
{
char[] c = new char[bytesToRead];
port.Read(c, 0, bytesToRead);
richTextBox1.Text += new string(c);//显示串口出来的数据
}
}