首次使用C#编写与COM口有关的程序,期间遇到了很多问题,写下自己的经验总结,如有错漏,欢迎批评指正!
1、新建一个串口类( SerialPort类)
1 //Create a serial port for bluetooth 2 SerialPort BluetoothConnection = new SerialPort();
2、串口端口号搜索:
string[] Ports = SerialPort.GetPortNames();
or (int i = 0; i < Ports.Length; i++)
{
string name = Ports[i];
comboBox.Items.Add(name);//显示在消息框里面
}
3、读数据、显示数据:
byte[] data = new