I'm Trying to read a 23 byte hex string Using Serial Port

  • Thread starter Thread starter Anuwat Ka
  • Start date Start date
A

Anuwat Ka

Guest
I'm trying to make an application that can read a 23 byte hex string from the serial port and cut some bytes to display into a text box.

like thie : 501004 185555E13301005. = 35 30 31 30 30 34 20 31 38 35 35 35 35 45 31 33 33 30 31 30 30 35 14

i want to display 5555E1301005

but not work because i can not cut last byte (14) in dec

Thanks.

sorry i don't good in english

The following is my code:

Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
ReceivedText(SerialPort1.ReadExisting())
End Sub

Private Data As New System.Text.StringBuilder
Private Sub ReceivedText(ByVal [text] As String)
If Me.TextBox1.InvokeRequired Then
Dim x As New SetTextCallBack(AddressOf ReceivedText)
Me.Invoke(x, New Object() {(text)})
Else
' Me.TextBox1.Text &= [text] '' Debug
Data.Append(text)
Dim StartIndex As Integer = Data.ToString.IndexOf("8")
If StartIndex > -1 Then
Dim EndIndex As Integer = Data.ToString.IndexOf(".", StartIndex)
If EndIndex > -1 Then
TextBox1.Text &= Data.ToString.Substring(StartIndex + 1, 12).Trim & vbNewLine
Data.Remove(0, EndIndex + 1)
End If
End If
Dim sent(0) As Byte ' for sent ack to device
sent(0) = &H6 ' for sent ack to device
SerialPort1.Write(sent, 0, sent.Length) ' for sent ack to device
End If
End Sub

Continue reading...
 
Back
Top