XBee robot

Another good one from our friend XBee Control of .NET Gadgeteer Robot | Integral Design

Good one!

Thanks! These Xbees are pretty cool. I want to network a bunch of them eventually. Also need to investigate their range.
I’m still wondering why I can’t use the line recieved event of the serial interface. Paul Mineau’s XbeeClient libraries solve the problem, but it baffles me why the serial interface is working in the debugger, but on autonomous power the line received event doesn’t fire.

@ Mike,
I don’t know if this is related, but there has been a long standing issue with attaching to the received event before opening the port. What you describe is typical of that, ie, the event fires while debugging, but not when run without the debugger…

To resolve this, first open the port, then attach to the event…

Thanks, Errol. I think I have tried this and gotten an error, but I’ll give it another shot.

The following code runs, and the DataReceived event fires, but the LineReceived event does not fire. If I try to open the serial line before I set the event handlers, I get an exsception on Open.

using Microsoft.SPOT;

using GT = Gadgeteer;
using Gadgeteer.Modules.GHIElectronics;

namespace HydraXbee
    public partial class Program
        GT.Interfaces.Serial serial;
        void ProgramStarted()
            serial = xBee.SerialLine;
            serial.LineReceived += new GT.Interfaces.Serial.LineReceivedEventHandler(serial_LineReceived);
            serial.AutoReadLineEnabled = true;
            serial.DataReceived += new GT.Interfaces.Serial.DataReceivedEventHandler(serial_DataReceived);
            Debug.Print("Program Started");

        void serial_DataReceived(GT.Interfaces.Serial sender, System.IO.Ports.SerialData data)
            Debug.Print("data received");

        void serial_LineReceived(GT.Interfaces.Serial sender, string line)

        void button_ButtonPressed(Button sender, Button.ButtonState state)
            Debug.Print("button pressed");

Hmm, what kind of error are you getting?

This is one example of past event problems:

It throws on initialization:

        private void ReadLineProcess()
            string outstandingText = String.Empty;
            byte[] buf = new byte[1];

            this._serialPort.ReadTimeout = 1000;  // <- exception here.