Hamza Abbasi
Hamza Abbasi

Reputation: 23

Convert Serially Read Data to HEX form

I am reading data from Serial port on click of a button by using Methods

byte[] query = new byte[8] { 0x01, 0x03, 0x00, 0x00, 0x00, 0x02, 0xC4, 0x0B };

serialPort1.Write(query, 0, query.Length);
incoming = serialPort1.ReadLine();
Textbox1.text=incoming;

I am storing the serially read data in variable Incoming i want this data to be converted in HEX form for further processing

Upvotes: 0

Views: 190

Answers (1)

Derviş Kayımbaşıoğlu
Derviş Kayımbaşıoğlu

Reputation: 30565

here is an example for Hex conversion

byte[] ba = Encoding.Default.GetBytes(incoming);
var hexString = BitConverter.ToString(ba);

Working Fiddle

Upvotes: 1

Related Questions