码迷,mamicode.com
首页 > Windows程序 > 详细

c#中串口接收事件处理

时间:2014-12-10 10:29:25      阅读:486      评论:0      收藏:0      [点我收藏+]

标签:ar   os   sp   for   on   bs   ad   new   nbsp   

1.缓冲区不定字节读取

byte[] data = new byte[serialPort1.BytesToRead]; //定义缓冲区,因为串口事件触发时有可能收到不止一个字节
serialPort1.Read(data, 0, data.Length);
foreach (byte Member in data) //遍历用法
{
string str = Convert.ToString(Member, 16).ToUpper();
textBox1.AppendText("0x" + (str.Length == 1 ? "0" + str : str) + " ");
}

2.单字节读取

   byte DataReceived = (byte)(serialPort1.ReadByte());                                           //单字节读取

c#中串口接收事件处理

标签:ar   os   sp   for   on   bs   ad   new   nbsp   

原文地址:http://www.cnblogs.com/fx427103/p/4154670.html

(1)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!