title: Receiving and Processing HEX data from Serial
body: <p>I'm new to this forum so I'm not sure if this is really the place to put this - feel free to move to a more appropriate forum if required.</p>
  
  <hr>
  
  <p>Okay so I'm writing a simple application in VB 2010 that sends and receives HEX data to a serial device. Now I have the "sending" part down pat, however, I'm having difficulty with the receiving part.  The device sends a constant stream of HEX data back to the application every second; I need the application to look at certain bytes of the received HEX string and do things accordingly within IF Statements (e.g. If byte 10 of the string is equal to "&amp;10" then do ... ).</p>
  
  <p>I'm not sure how to get this data, parse the correct byte out of it and then do something with it. :/ The code I've attempted to use for this (but does not work) is as follows:-</p>
  
  <pre><code>Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As     System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
         Dim statusget() As String
         Dim str1 As String
         str1 = SerialPort1.ReadExisting()
         statusget = str1.Split(",")
  
      If statusget(10) = "&amp;01" Then
          btn_tx1.BackColor = Color.Red
          btn_tx2.BackColor = SystemColors.Control
          btn_tx3.BackColor = SystemColors.Control
          btn_tx4.BackColor = SystemColors.Control
          btn_tx5.BackColor = SystemColors.Control
          btn_tx6.BackColor = SystemColors.Control
          btn_tx7.BackColor = SystemColors.Control
          btn_tx8.BackColor = SystemColors.Control
      End If
  End Sub
  </code></pre>
  
  <p>Additionally, I have a Rich-Text box that displays all data received from the device so I can monitor it.  It works fine, except for the fact that it returns in a weird encoding (not HEX) such as "uZ!!!??".</p>
  
  <p>Thank you for any help you can provide. :)</p>
  
  <hr>
  
  <p><strong>Edit - Code for Sending data:</strong></p>
  
  <pre><code>Private Sub btn_tx1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_tx1.Click
      Dim buftx1() As Byte = {&amp;HF0, &amp;H5A, &amp;HF, &amp;H5, &amp;H1, &amp;H11, &amp;H0, &amp;H0, &amp;H0, &amp;H0, &amp;H0, &amp;H0, &amp;H30, &amp;H37, &amp;HFF}
      SerialPort1.Write(buftx1, 0, buftx1.Length)
  End Sub
  </code></pre>