Hello everybody, I don’t know if this is the right place to be asking my questions, but I hope someone can guide me in the right direction.
Equipment:
Xbee type: XB24
Xbee pro type: XBP24
Development kit board with USB to my laptop computer
Another development kit board with a loopback.
The Xbee pro is sending to the normal Xbee.
I’m trying to make a program in visual basic to split the received data into understandable segments. I have managed to get some kind of reading into the computer, but I am having huge problems understanding the data.
I am a newbie at VB-programming, so I could be way of target in my code. That is why I’m posting here, I don’t want to spend hours programming only to find out that I need to do everything over again because I’m doing it all wrong.
What I want the code to do, is collect data from the Xbee. I have found this website:
http://www.digi.com/support/kbase/kbase … jsp?kb=188
I’m not sure that the information about the datastream here is correct, but it is a good start.
What I’m trying to do is collect all that information, and split it up.
Here is my go at splitting it up:
Imports System
Imports System.IO
Imports System.IO.Ports
Public Class Form1
    Dim bytes(13) As Byte
    Dim offset As Integer = 0
    Dim count As Integer = 14
    Dim resulttype As String
    Dim WithEvents xbee As New SerialPort
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        xbee.BaudRate = 9600
        xbee.PortName = "com4"
        xbee.Parity = Parity.Even
        xbee.StopBits = 1
        xbee.DataBits = 8
    End Sub
    
    Private Sub timer1_tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Received.Clear()
        Try
            xbee.Open()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Dim Data
        xbee.Read(bytes, offset, count)
        'Data = Data & " "
        'Received.AppendText(Data)
        For i As Integer = 0 To 13
            resulttype = invenum(i)
            Data = bytes(i)
            Received.AppendText(resulttype & ": |  " & Data & vbNewLine)
        Next
        Try
            xbee.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Private Sub btnRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRead.Click
        If Timer1.Enabled = False Then
            Timer1.Enabled = True
        Else
            Timer1.Enabled = False
        End If
    End Sub
    Public Function invenum(ByVal i As Integer)
        Select (i)
            Case 0 : Return "Start delimiter"
            Case 1 : Return "Length byte 1"
            Case 2 : Return "length byte 2"
            Case 3 : Return "API identifier byte"
            Case 4 : Return "Source address byte 1"
            Case 5 : Return "Source address byte 2"
            Case 6 : Return "RSSI value byte"
            Case 7 : Return "Option byte"
            Case 8 : Return "Sample quantity byte"
            Case 9 : Return "Channel indicator 1"
            Case 10 : Return "Channel indicator 2"
            Case 11 : Return "Sample data 1"
            Case 12 : Return "Sample data 2"
            Case 13 : Return "Checksum"
        End Select
    End Function
End Class