【实例简介】
【实例截图】
【核心代码】
using System;
using System.IO.Ports;
using System.Linq;
using System.Windows.Forms;
//使用C#自带serialPort控件进行串口编程94011.com.cn
namespace serialport
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
//使用委托进行跨线程读取数据
Invoke
(new EventHandler
(delegate
{
txtreceived.Text = comport .ReadExisting ();
}
)
);
}
private void Form1_Load(object sender, EventArgs e)
{
foreach (string com in System .IO .Ports .SerialPort.GetPortNames ()) //自动获取串行口名称
<