how can I display data, I received on SerialPort, in a raw hex byte format ?
It took me several approaches to convert the data basically, but there still seems to be an ASCII / UTF7 / UTF8 problem. I am now using a byte array instead of a former char-array, but still I don't get any value larger than 127 dec (0x7F). When sending decimal 128, I receive 0x3F on RX-Side.
Here's the current DataReceiveHandler:
C# |
Does anybody know how to display the hex values for incoming bytes from 0x80 up to 0xFF ?

Hansi Mausi4 reputationPosted Sep 7, 2010, 12:42 AM EDT
I have to use
public int ReadByte() instead of public string ReadExisting()Here's the code:
{
Thread.Sleep(200);
string bytestr = "";
int numbytes = _portB.BytesToRead;
byte[] rxbytearray = new byte[numbytes];
for(int i = 0; i
rxbytearray[i] = (byte)_portB.ReadByte();
}
string hexvalues = "";
foreach (byte b in rxbytearray)
{
if(b != '\r')
hexvalues = hexvalues + (b.ToString("X2")) + " ";
}
UpdGuiEvent.Invoke(hexvalues);
}