#Region "HexToByte"
Public Function HexToByte(ByVal msg As String) As Byte()
If msg.Length Mod 2 = 0 Then
_msg = msg
_msg = msg.Replace(" ", "")
Dim comBuffer As Byte() = New Byte(_msg.Length / 2 - 1) {}
For i As Integer = 0 To _msg.Length - 1 Step 2
comBuffer(i / 2) = CByte(Convert.ToByte(_msg.Substring(i, 2), 16))
Next
write = True
Return comBuffer
Else
Return Nothing
End If
End Function
#End Region
#Region "ByteToHex"
Public Function ByteToHex(ByVal comByte As Byte()) As String
Dim builder As New StringBuilder(comByte.Length * 3)
For Each data As Byte In comByte
builder.Append(Convert.ToString(data, 16).PadLeft(2, "0"c).PadRight(3, " "c))
Next
Return builder.ToString().ToUpper()
End Function
#End Region