C# serialport控件怎么使用啊?
发布网友
发布时间:2024-10-08 05:43
我来回答
共2个回答
热心网友
时间:2024-11-20 08:30
首先是打开串口:
serialPort1.PortName = portList.SelectedItem.ToString();
serialPort1.BaudRate = Convert.ToInt32(baudrateList.SelectedItem.ToString());
serialPort1.StopBits = StopBits.One;
serialPort1.Parity = Parity.None;
serialPort1.DataBits = 8;
serialPort1.Handshake = Handshake.None;
this.serialPort1.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);
serialPort1.Open();
然后就是数据的接收了:
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
string readString = serialPort1.ReadExisting();
}
然后就自己组织一下吧,我只是截取了片段的代码。
热心网友
时间:2024-11-20 08:30
http://www.cnblogs.com/tuyile006/archive/2006/09/29/517882.html
自己去看,其实串口开发就是两个方法的问题,首先初始化串口,然后打开,再发送数据,接收数据。就这样,so easy!