i have designed a program by C# to read the received data from a Machine by serial port. the received data is Hex i want to change it to AscII then Split it to different text box. when it comes to one textBox there is no problem but when i am trying to change it to Ascii or split it, the program stop working
i appreciate any support
the code in one text box works well. my problems are changing to ascii and splitting the received data to several text box
public void serialPort1_DataReceived(object sender,
SerialDataReceivedEventArgs e)
{
SerialPort serialPort1 = (SerialPort)sender;
int numbytes = serialPort1.BytesToRead;
byte[] rxbytearray = new byte[numbytes];
for (int i = 0; i < numbytes; i++)
{
rxbytearray[i] = (byte)serialPort1.ReadByte();
}
foreach (byte b in rxbytearray)
{
hexvalues = (hexvalues + b.ToString("X2")) + " ";
}
this.Invoke(new EventHandler(Showdata));
}
private void Showdata(object sender, EventArgs e)
{
tBoxDataIn.Text = hexvalues + "\r\n";
char[] chars = hexvalues.ToCharArray();
for (int i =2; i < 7; i++)
{
xy = xy + chars[i];
}
string Cpfdecimal = Convert.ToUInt64(xy, 16).ToString();
textBox1.Text = Cpfdecimal;
}
public string ConvertHextoAscii()
{
char charValue;
string stringValue = "";
string[] hexValuesSplit = tBoxDataIn.Text.Split(' ');
foreach (string hex in hexValuesSplit)
{
// Convert the number expressed in base-16 to an integer.
int value = Convert.ToInt32(hex, 16);
// Get the character corresponding to the integral value.
stringValue = Char.ConvertFromUtf32(value);
charValue = (char)value;
}
textBox1.Text = stringValue;
return stringValue;
}
the hex received data: 0D 53 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 45 0D 0D
i want to change it to Ascii and split it.