Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
Hi, I designed an application in order to make data exchange , I developed an application in C # , I can sent and receive data as well, but the problem is that I get the data as character ASCII . I would like to receive the data in HEX byte by byte , I searched the in the net but I have not found a solution , so I would like if some one help and how to receive the data IN hexa byte .

Here is my piece of code to receive the data

C#
String data;
    private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
    {
        data += serialPort1.ReadExisting();
        this.Invoke(new EventHandler(display_data_event));
    }
 
    private void display_data_event(object sender, EventArgs e)
    {
        textBox2.Text = data;
    }
Posted
Updated 2-May-16 8:47am
v2

1 solution

Then stop reading the data as a string, and read it as bytes: SerialPort.Read Method (Byte[], Int32, Int32) (System.IO.Ports)[^]
 
Share this answer
 
Comments
Jammes_Ca 2-May-16 14:50pm    
Thanks, but how do i use the exampel in my code ? :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900