非原创。
接收16进制数据,在TextBox委托显示:
private void readPortandShow() { char[] HexChar = { ‘0‘, ‘1‘, ‘2‘, ‘3‘, ‘4‘, ‘5‘, ‘6‘, ‘7‘, ‘8‘, ‘9‘, ‘A‘, ‘B‘, ‘C‘, ‘D‘, ‘E‘, ‘F‘ }; byte receivebyte = (byte)serialPort1.ReadByte(); char hexH = HexChar[receivebyte / 16]; char hexL = HexChar[receivebyte % 16]; this.tBox.Invoke(new MethodInvoker(delegate { this.tBox.AppendText(hexH.ToString() + hexL.ToString() + " "); })); }
时间: 2024-10-26 10:47:56