Main Site Documentation

FEZ Raptor - USB Host with netmf 4.3 Exception


#1

Attached code shows the problem. I have no idea what is going on or how to correct it.



using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Shapes;
using Microsoft.SPOT.Touch;

using GT = Gadgeteer;
using Gadgeteer.Modules.GHIElectronics;
using GHI.Usb.Host;

/*
    Using VS 2012 For Desktop on Windows 8.1 with all the latest updates
    Using FEZ Raptor Rev 1.0 with G400-S V1.1
    usbHost Socket 7
    usbClientDP Socket 8 
*/

namespace G400test
{
    public partial class Program
    {
        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            usbHost.MassStorageMounted += usbHost_MassStorageMounted;
            usbHost.MassStorageUnmounted += usbHost_MassStorageUnmounted; // This causes NULL exception
            Debug.Print("** Program Started");
        }
        //
       
        /*
            The thread '<No Name>' (0x2) has exited with code 0 (0x0).
            Using mainboard GHI Electronics FEZ Raptor version 1.0
            ** Program Started
            ** usbHost MassStorageMounted
            The thread '<No Name>' (0x3) has exited with code 0 (0x0).
                #### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
                #### Message: 
                #### GHI.Usb.Host.BaseDevice::OnDisconnected [IP: 0017] ####
                #### GHI.Usb.Host.Controller::OnDisconnect [IP: 002b] ####
                #### GHI.Utilities.InternalEvent::RaiseEvent [IP: 000d] ####
                #### GHI.Utilities.InternalEvent::OnEvent [IP: 0035] ####
            A first chance exception of type 'System.NullReferenceException' occurred in GHI.Usb.dll
            An unhandled exception of type 'System.NullReferenceException' occurred in GHI.Usb.dll
         */
        void usbHost_MassStorageUnmounted(USBHost sender, EventArgs e)
        {
            //Added try/catch but NULL error is received before this method is entered? 
            try
            {
                Debug.Print("** usbHost MassStorageUnmounted");
            }
            catch (System.NullReferenceException err)
            {
                Debug.Print(err.Message);
            }
        }
        //

        //Called on program startup if Flash is already inserted //No exception received
        //Called after program startup when Flash is inserted    //No exception received
        void usbHost_MassStorageMounted(USBHost sender, GT.StorageDevice device)
        {
            Debug.Print("** usbHost MassStorageMounted");
        }
        //
    }
}
//


I must mention that the VS 2012 Express For Desktop on Windows 8.1 was installed after my recent purchase of Visual Studio 2013 Pro. I had removed all Express versions I had before installing 2013 Pro. After it was installed I downloaded and installed it Express 2012.

I only mention this because debugging seems a bit different than when I only had the VS 2012 Express.

It appears to me that VS 2012 Express For Desktop is somehow tied into my Full version of 2013 Pro. Maybe not but I think so…

Thanks for any thoughts on why I get this null exception

EDIT:
I forgot to mention that if I have button events… And use Controller

Controller.DeviceConnectFailed += Controller_DeviceConnectFailed;
Controller.Start();

I no longer receive the events…


#2

@ willgeorge - That was a bug that has been fixed for the next release. You can try to use USB Host without the Gadgeteer module in the designer if you need to work around the exception.


#3

@ John -

Thank you for the quick reply!