C#serialport控件详细用法
1个回答
展开全部
首先是打开串口:
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();
}
然后就自己组织一下吧,我只是截取了片段的代码。
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();
}
然后就自己组织一下吧,我只是截取了片段的代码。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询