FEZ Cerberus with XBee RN-XV fails on SerialPort.Open()

I keep getting an System.InvalidOperationException when trying to SerialPort.Open() on a FEZ Cerberus (non-Bee). I have the same code (almost) working fine on a FEZ Cerberus Bee.

Code on the FEZ Cerberus Bee:

_wifi = new WiFlyGSX();

Code on the FEZ Cerberus:

xBeeAdapter.Configure(9600, GT.SocketInterfaces.SerialParity.None, GT.SocketInterfaces.SerialStopBits.One, 8, GT.SocketInterfaces.HardwareFlowControl.Required);
            xBeeAdapter.DebugPrintEnabled = true;
            string port = xBeeAdapter.Port.PortName;
            Debug.Print("xBeeAdapter on Port: " + port);
            _wifi = new WiFlyGSX(port, 9600, "$", false);

The Exception occurs inside the WiFlyGSX (a .netmftoolbox class) constructor where it try to open the serial port.

            // Configures this client
            this._CommandMode_InitString = CommandChar + CommandChar + CommandChar;
            this.DebugMode = DebugMode;
            this._Mode = Modes.Idle;

            // Configures and opens the port
            this._SerialPort = new SerialPort(PortName, BaudRate, Parity.None, 8, StopBits.One);
            this._SerialPort.DataReceived += new SerialDataReceivedEventHandler(_SerialPort_DataReceived);

I have tried various flowcontrol configurations, and nothing seems to make a difference. The xBeee adapter is showing up on COM2.

---- Output -----
Using mainboard GHI Electronics FEZ Cerberus version 1.3
Initializing WiFi
xBeeAdapter on Port: COM2
A first chance exception of type ‘System.InvalidOperationException’ occurred in Microsoft.SPOT.Hardware.dll

Anyone have any thoughts?

Hello, welcome to the forum.
Some thoughts, but I don’t know if they are right.
Perhaps the exception is thrown because you initialize the Serial port twice.
The first time with :


the second time in the constructor of the WiFlyGSX Class.

Perhaps it works if you leave the first initialization away and call the constructor of the WiFlyGSX Class with:

_wifi = new WiFlyGSX("COM2", 9600, "$", false);

Fantastic RoSchmi! That was indeed it!

Good catch. I never would have considered that.

BTW - I have only gotten to work for far at 57600 (not 9600).

Thanks so much for your help.

Glad to hear, that it works for you.
BTW: The baudrate of 57600 is quite good to communicate with the RN-XV.
If you want to change the baudrate of the RN-XV you can use my Codeshare contribution. However my mechanism of changing the baudrate does not work absolutely reliable:


I’m looking forward to see your project on Codeshare.