c# serialport读取不限数量的16进制数据

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//private char[] HexChar = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
 
 private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            char hexH;
            char hexL;
            byte receivebyte;
            string dataToshow = "";
            while (serialPort1.BytesToRead > 0)
            {
                receivebyte = (byte)serialPort1.ReadByte();
                hexH = HexChar[receivebyte / 16];
                hexL = HexChar[receivebyte % 16];
                dataToshow += hexH.ToString() + hexL.ToString();
            }
            this.tBox.Invoke(new MethodInvoker(delegate
            {
                this.tBox.AppendText(dataToshow + "\n");
            }));
        }

  

posted @   Joanna-In-Hdu&Hust  阅读(1360)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示