C# Serial Port reading HEX data

 ̄綄美尐妖づ 提交于 2019-12-06 14:15:55

Alex Farber's method works. Below is my code example:

SerialPort sp = (SerialPort) sender;
// string s = sp.ReadExisting();
// labelSerialMessage.Invoke(this.showSerialPortDelegate, new object[] { s });

int length = sp.BytesToRead;
byte[] buf = new byte[length];

sp.Read(buf, 0, length);
System.Diagnostics.Debug.WriteLine("Received Data:" + buf);

labelSerialMessage.Invoke(this.showSerialPortDelegate, new object[] { 
    System.Text.Encoding.Default.GetString(buf, 0, buf.Length) });
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!