C#的serialPort空间使用
答案:1 悬赏:60 手机版
解决时间 2021-03-23 15:12
- 提问者网友:杀生予夺
- 2021-03-22 18:19
C#的serialPort空间使用
最佳答案
- 五星知识达人网友:拜訪者
- 2021-03-22 19:00
首先是打开串口:
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();
}
然后就自己组织一下吧,我只是截取了片段的代码。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯