Hi, everyone! i got some problem about vb.net Serial port, hope you guys can help me :)
i want to write a program to receive hex code from machine. The machine non stop every second send out 48byte hex code.
so i need to capture all 48 hex code per second. the hex look like below:
986700272700000000800080000000000000000000000000986800272700000000800002000000000000000000000000
how can i receive all 48 hex code, and show in textbox1?
and then how can i capture 10th, 11th and 12th hex code show in textbox2?
i'm write the code can capture the hex code but cant store complete 48 byte hex code.
here is my vb.net code:
please help me.
thank!
i want to write a program to receive hex code from machine. The machine non stop every second send out 48byte hex code.
so i need to capture all 48 hex code per second. the hex look like below:
986700272700000000800080000000000000000000000000986800272700000000800002000000000000000000000000
how can i receive all 48 hex code, and show in textbox1?
and then how can i capture 10th, 11th and 12th hex code show in textbox2?
i'm write the code can capture the hex code but cant store complete 48 byte hex code.
here is my vb.net code:
Code:
Private Sub SerialPort1_DataReceived(sender As Object, e As SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
UpdateFormDelegate1 = New UpdateFormDelegate(AddressOf UpdateDisplay)
Dim n As Integer = SerialPort1.BytesToRead 'find number of bytes in buf
comBuffer = New Byte(n - 1) {} 're dimension storage buffer
SerialPort1.Read(comBuffer, 0, n) 'read data from the buffer
Me.Invoke(UpdateFormDelegate1) 'call the delegate
End Sub
Private Sub UpdateDisplay()
On Error GoTo handle
Dim num1, num2, num3, str1, str2, str3 As String
Dim lngpos As Long
num2 = ""
For i = LBound(comBuffer) To UBound(comBuffer)
num1 = Hex(comBuffer(i))
If Len(num1) = 1 Then
num2 = "0" & num1
Else
num2 = num1
End If
Next
TextBox1.Text &= num2 'store all hex code
num3 = TextBox1.Text
lngpos = InStr(num3, 80)
str1 = Mid$(num3, lngpos, 6)
TextBox2.Text = str1
end sub
thank!