Main Site Documentation

Mounting a USB drive


#1

I am running a domino with the 128x64 graphics display. This is the code I am trying to use.

using System;
using System.IO;
using System.Threading;

using Microsoft.SPOT;
using Microsoft.SPOT.IO;
using Microsoft.SPOT.Hardware;

using GHIElectronics.NETMF.FEZ;
using GHIElectronics.Graphics.Simple128x64;
using GHIElectronics.NETMF.IO;
using GHIElectronics.NETMF.USBHost;


namespace FEZ_Domino_Application1
{
    public class Program
    {
        public static void Main()
        {

            // Init Display
            FEZ_Extensions.Graphical128x64Display.Initialize(FEZ_Pin.Digital.UEXT3, FEZ_Pin.Digital.UEXT4, FEZ_Pin.Digital.UEXT10, SPI.SPI_module.SPI2);

            // Display FEZ message
            FEZ_Extensions.Graphical128x64Display.Print(0, 1, "File Transfer Station");
            FEZ_Extensions.Graphical128x64Display.Print(9, 4, "UNLV Senior Design");

            Thread.Sleep(100);

            
            // Subscribe to RemovableMedia events
            RemovableMedia.Insert += RemovableMedia_Insert;
            RemovableMedia.Eject += RemovableMedia_Eject;

            // Subscribe to USB events
            USBHostController.DeviceConnectedEvent += DeviceConnectedEvent;
            // Sleep forever
            Thread.Sleep(Timeout.Infinite);
        }

        static void DeviceConnectedEvent(USBH_Device device)
        {
            if (device.TYPE == USBH_DeviceType.MassStorage)
            {
                Debug.Print("USB Mass Storage detected...");

                GPainter paint = new GPainter();
                paint.Clear();
                paint.PrintSmall(0, 1, "USB device detected");
                //....
                //....
            }
        }
    }
}

Visual studios is coming back to me and giving the following errors:

Error 1 The name ‘RemovableMedia_Insert’ does not exist in the current context C:\Users\Aaron\documents\visual studio 2010\Projects\Program.cs 33 38 FEZ Domino Application1

Error 2 The name ‘RemovableMedia_Eject’ does not exist in the current context C:\Users\Aaron\documents\visual studio 2010\Projects\Program.cs 34 37 FEZ Domino Application1

Error 3 No overload for ‘DeviceConnectedEvent’ matches delegate ‘GHIElectronics.NETMF.USBHost.USBH_DeviceConnectionEventHandler’ C:\Users\Aaron\documents\visual studio 2010\Projects\Program.cs 37 55 FEZ Domino Application1

Error 4 The type or namespace name ‘USBH_Device’ could not be found (are you missing a using directive or an assembly reference?) C:\Users\Aaron\documents\visual studio 2010\Projects\Program.cs 42 42 FEZ Domino Application1

Error 5 The name ‘USBH_DeviceType’ does not exist in the current context C:\Users\Aaron\documents\visual studio 2010\Projects\Program.cs 44 32 FEZ Domino Application1

It seems that this would be an error from me not including the proper files into the project, however I have placed these files in code as well as in the references section. Could it be that I need to insert another .cs file or something into my project? I am still very new to c#. I will include a image of my solutions explorer window if that might help to see how I have this configured.

Regards,
Aaron


#2

RemovableMedia.Insert += new InsertEventHandler(RemovableMedia_Insert);

You have to add it as an event handler on lines 30, 31 and 34. That’s a start… still looking at the rest of your code


#3

Also, are you using the 4.1 framework?


#4

I have installed the 4.1 .net sdk, I believe this is the 4.1 framework.


#5

Ok, you’re also missing a reference to the GHIElectronics.NETMF.System libary

Here is some modified code (you will need to implement the event handlers)


using System;
using System.IO;
using System.Threading;

using Microsoft.SPOT;
using Microsoft.SPOT.IO;
using Microsoft.SPOT.Hardware;

using GHIElectronics.NETMF.FEZ;
using GHIElectronics.Graphics.Simple128x64;
using GHIElectronics.NETMF.IO;
using GHIElectronics.NETMF.USBHost;


namespace FEZ_Domino_Application1 {
    public class Program {
        public static void Main() {

            // Init Display
            FEZ_Extensions.Graphical128x64Display.Initialize(FEZ_Pin.Digital.UEXT3, FEZ_Pin.Digital.UEXT4, FEZ_Pin.Digital.UEXT10, SPI.SPI_module.SPI2);

            // Display FEZ message
            FEZ_Extensions.Graphical128x64Display.Print(0, 1, "File Transfer Station");
            FEZ_Extensions.Graphical128x64Display.Print(9, 4, "UNLV Senior Design");

            Thread.Sleep(100);


            // Subscribe to RemovableMedia events
            RemovableMedia.Insert += new InsertEventHandler(RemovableMedia_Insert);
            RemovableMedia.Eject += new EjectEventHandler(RemovableMedia_Eject);

            // Subscribe to USB events
            USBHostController.DeviceConnectedEvent += new USBH_DeviceConnectionEventHandler(USBHostController_DeviceConnectedEvent);
            // Sleep forever
            Thread.Sleep(Timeout.Infinite);
        }

        static void USBHostController_DeviceConnectedEvent(GHIElectronics.NETMF.USBHost.USBH_Device device) {
            throw new NotImplementedException();
        }


        static void RemovableMedia_Eject(object sender, MediaEventArgs e) {
            throw new NotImplementedException();
        }

        static void RemovableMedia_Insert(object sender, MediaEventArgs e) {
            throw new NotImplementedException();
        }

        static void DeviceConnectedEvent(USBH_Device device) {
            if (device.TYPE == USBH_DeviceType.MassStorage) {
                Debug.Print("USB Mass Storage detected...");

                GPainter paint = new GPainter();
                paint.Clear();
                paint.PrintSmall(0, 1, "USB device detected");
                //....
                //....
            }
        }
    }
}

Don’t forget that it’s plus, equal, tab, tab to create the event handers automatically…

+={tab}{tab}


#6

Thank you, that got out the immediate errors. I am going to read about some event handlers now so I can understand what I am doing. ;D


#7
using System;
using System.IO;
using System.Threading;

using Microsoft.SPOT;
using Microsoft.SPOT.IO;
using Microsoft.SPOT.Hardware;

using GHIElectronics.NETMF.FEZ;
using GHIElectronics.Graphics.Simple128x64;
using GHIElectronics.NETMF.IO;
using GHIElectronics.NETMF.USBHost;
using GHIElectronics.NETMF.System;

namespace FEZ_Domino_Application1
{
    public class Program
    {
        public static void Main()
        {

            // Init Display
            FEZ_Extensions.Graphical128x64Display.Initialize(FEZ_Pin.Digital.UEXT3, FEZ_Pin.Digital.UEXT4, FEZ_Pin.Digital.UEXT10, SPI.SPI_module.SPI2);

            // Display FEZ message
            FEZ_Extensions.Graphical128x64Display.Print(0, 1, "File Transfer Station");
            FEZ_Extensions.Graphical128x64Display.Print(9, 4, "UNLV Senior Design");

            Thread.Sleep(100);


            // Subscribe to RemovableMedia events
            RemovableMedia.Insert += new InsertEventHandler(RemovableMedia_Insert);
            RemovableMedia.Eject += new EjectEventHandler(RemovableMedia_Eject);

            // Subscribe to USB events
            USBHostController.DeviceConnectedEvent += new USBH_DeviceConnectionEventHandler(USBHostController_DeviceConnectedEvent);
            // Sleep forever
            Thread.Sleep(Timeout.Infinite);
        }

        static void USBHostController_DeviceConnectedEvent(GHIElectronics.NETMF.USBHost.USBH_Device device)
        {
            //throw new NotImplementedException();
            Debug.Print("USB Mass Storage connected...");

            GPainter paint = new GPainter();
            paint.Clear();
            paint.PrintSmall(0, 1, "USB device connected");
        }


        static void RemovableMedia_Eject(object sender, MediaEventArgs e)
        {
            //throw new NotImplementedException();
            Debug.Print("USB Mass Storage ejected...");

            GPainter paint = new GPainter();
            paint.Clear();
            paint.PrintSmall(0, 1, "USB device ejected");
        }

        static void RemovableMedia_Insert(object sender, MediaEventArgs e)
        {
            //throw new NotImplementedException();
            Debug.Print("USB Mass Storage inserted...");

            GPainter paint = new GPainter();
            paint.Clear();
            paint.PrintSmall(0, 1, "USB device inserted");
        }

        static void DeviceConnectedEvent(USBH_Device device)
        {
            if (device.TYPE == USBH_DeviceType.MassStorage)
            {
                Debug.Print("USB Mass Storage detected...");

                GPainter paint = new GPainter();
                paint.Clear();
                paint.PrintSmall(0, 1, "USB device detected");
                //....
                //....
            }
        }
    }
}

I am trying to handling the events in this manner, I am not getting any response on the LCD when i try inserting and removing the USB drive.


#8

I did try your code, but without the Graphics LCD.

It worked fine without any alteration at all.
One thing that I noticed the different was in your References.

If you add

GHIElectronics.NETMF.System

to the References you should be fine with your existing code.

using System;
using System.IO;
using System.Threading;
 
using Microsoft.SPOT;
using Microsoft.SPOT.IO;
using Microsoft.SPOT.Hardware;
 
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.Graphics.Simple128x64;
using GHIElectronics.NETMF.IO;
using GHIElectronics.NETMF.USBHost;
 
 
namespace FEZ_Domino_Application1 {
    public class Program {
        public static void Main() {

            // Subscribe to RemovableMedia events
            RemovableMedia.Insert += new InsertEventHandler(RemovableMedia_Insert);
            RemovableMedia.Eject += new EjectEventHandler(RemovableMedia_Eject);
 
            // Subscribe to USB events
            USBHostController.DeviceConnectedEvent +=  DeviceConnectedEvent);

            // Sleep forever
            Thread.Sleep(Timeout.Infinite);
        }
 
        static void DeviceConnectedEvent(USBH_Device device) {
            if (device.TYPE == USBH_DeviceType.MassStorage) {
                Debug.Print("USB Mass Storage detected...");
 
                GPainter paint = new GPainter();
                paint.Clear();
                paint.PrintSmall(0, 1, "USB device detected");
                //....
                //....
            }
        }
    }
}

#9

I have since placed the GHIElectronics.NETMF.System to the references and it compiles without error. Since C# complains at any sight of error im assuming it is working, however I am not getting any feedback on the LCD, which I am guessing because it does not exist in the scope of the event handlers.


#10

You needed to add this line in the code
FEZ_Extension.Graphicsal128x64Display.Flush(paint.vram);
in the DeviceConnectedEvent() method.

like this:

        static void DeviceConnectedEvent(USBH_Device device) {
            if (device.TYPE == USBH_DeviceType.MassStorage) {
                Debug.Print("USB Mass Storage detected...");
 
                GPainter paint = new GPainter();
                paint.Clear();
                paint.PrintSmall(0, 1, "USB device detected");

                // this line need to be added
                FEZ_Extension.Graphicsal128x64Display.Flush(paint.vram);
                //....
                //....
            }

#11

Yup, that did it, thanks for the help =)


#12

my pleasure! :wink:

Hope to see you project post on the Projects page, soon.