Visual Basic Application - For anybody that wants to send data to Xbee

I’ve been trying to communcate in API mode to my Xbee from a PC for a while now. My biggest problem has been the actual sending of Hex data, for some reason Visual Basic only likes to send string data. I finally got it to work and here’s what I used:

CODE:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

Dim TestData() As Byte = {&HFE, &H11, &H11, &HFF}

'Dim TestData(3) As Byte

'TestData(0) = &HFE

'TestData(1) = &H11

'TestData(2) = &H11

'TestData(3) = &HFF

SerialPort.Write(TestData, 0, 4)

End Sub

Thanks for posting that! I’m sure that will be very useful to others in the VB world so its nice of you to post your solution here :slight_smile:

how can i enter into command mode in visual basic? hope you will reply thanks

hi,

am trying to send data to my xbee through vb express 2008 too, well am trying to switch on and off an led from an xbee cnnected via usb cable to my pc and an idle xbee which is powered by a 3.3V battery and has only an led soldered through the pin 20 via a resistor to pin 1 of the xbee
but the codes am sending is like ;
SerialPort1.Write(ATD0=4) ’ switch on the LED
SerialPort1.Write(ATD0=5) ’ switch off the LED

the thing is that its not working at all.

am guessing that maybe both xbees have been wrongly configured in the x-ctu software.

what should be the correct configuration?

by the way am using xbee s1 modules

thanks

I have written several .NET applications for XBee, including VB.NET. When sending API data using the serial port control, I usually place the bytes inside of an array and then send them out, much like HarrisnHJones.

Here’s the array I created to use the transmit request API frame (0x10) to send an ASCII “1”:

Dim ar1 As Byte() = {&H7E, &H0, &HF, &H10, &H1, &H0, &H0, &H0, &H0, &H0, &H0, &HFF, &HFF, &HFF, &HFE, &H0, &H0, &H31, &HC2}
sp.Write(ar1, 0, 19)