Stopping USBC_MassStorage

I have successfully enabled my Panda II to act as a USB Mass Storage device; I have to reset the device and short MOD to ground FYI. Now, I want the MassStorage to stop on the push of the LDR button so that I can access the files on the SD card.

I have tried calling disablelun(); when the button is pushed, but that doesn’t seem to stop MS it just seems to make the SD card Inaccessible.

I have more to the code, but I will show below what I have concerning this…

public class Program
    {

        static PersistentStorage sdCard;
        static USBC_MassStorage sdStorage;
        public static void Main()
        {
            InterruptPort IntButton = new InterruptPort((Cpu.Pin)FEZ_Pin.Digital.LDR, false,
                                                        Port.ResistorMode.PullUp,
                                                        Port.InterruptMode.InterruptEdgeLow);

            IntButton.OnInterrupt += new NativeEventHandler(IntButton_OnInterrupt);

            //"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

            sdCard = new PersistentStorage("SD");

            sdStorage = USBClientController.StandardDevices.StartMassStorage();

            sdStorage.AttachLun(0, sdCard, " ", " ");

            sdStorage.EnableLun(0);

            Thread.Sleep(Timeout.Infinite);
        }

        static void IntButton_OnInterrupt(uint port, uint state, DateTime time)
        {
            sdStorage.DisableLun(0);

Check the documentation it shows how to do exactly that.

I think you are missing the code where you supposed to mount the file system from sd card in order to access it.

See example at the bottom of the page:

http://www.ghielectronics.com/downloads/NETMF/Library%20Documentation%20v4.1/html/607ac9a8-62a0-ad43-cd1c-3034863c1b46.htm

@ Architect - I believe I do just that. Here is my full code. I have reviewed that document, but I don’t know what I am missing

namespace FEZ_Panda_II_Application1
{
    public class Program
    {

        static PersistentStorage sdCard;
        static USBC_MassStorage sdStorage;
        public static void Main()
        {
            InterruptPort IntButton = new InterruptPort((Cpu.Pin)FEZ_Pin.Digital.LDR, false,
                                                        Port.ResistorMode.PullUp,
                                                        Port.InterruptMode.InterruptEdgeLow);

            IntButton.OnInterrupt += new NativeEventHandler(IntButton_OnInterrupt);

            //"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

            sdCard = new PersistentStorage("SD");

            sdStorage = USBClientController.StandardDevices.StartMassStorage();

            sdStorage.AttachLun(0, sdCard, " ", " ");

            sdStorage.EnableLun(0);

            Thread.Sleep(Timeout.Infinite);
        }

        static void IntButton_OnInterrupt(uint port, uint state, DateTime time)
        {
            sdStorage.DisableLun(0);

            SerialPort UART = new SerialPort("COM1", 2400);

            int counter = 0;
            UART.Open();

            // ...
            // SD Card is inserted
            // Create a new storage device
            PersistentStorage sdPS = new PersistentStorage("SD");

            // Mount the file system
            sdPS.MountFileSystem();


            // Assume one storage device is available, access it through 
            // Micro Framework and display available files and folders:
            Debug.Print("Getting files and folders:");
            if (VolumeInfo.GetVolumes()[0].IsFormatted)
            {
                string rootDirectory =
                    VolumeInfo.GetVolumes()[0].RootDirectory;
                string outstr = "Files in " + rootDirectory + "\r\n";
                string[] files = Directory.GetFiles(rootDirectory);
                UART.Write(UTF8Encoding.UTF8.GetBytes(outstr), 0, outstr.Length);

                Debug.Print("Files available on " + rootDirectory + ":");
                for (int i = 0; i < files.Length; i++)
                {
                    Debug.Print(files[i]);
                    outstr = files[i] + "\r\n";
                    UART.Write(UTF8Encoding.UTF8.GetBytes(outstr), 0, outstr.Length);


                }

            }
        }
    }
}

I think this is normal. This is liek if you removed SD card from USB reader. The reader is there but SD was removed, which is what you need.

try disposing sdCard before creating another persistence storage object? and sdStorage…

Or just replace

            
            // SD Card is inserted
            // Create a new storage device
            PersistentStorage sdPS = new PersistentStorage("SD");
 
            // Mount the file system
            sdPS.MountFileSystem();

with this:

sdCard.MountFileSystem();

@ Architect - Okay, I just tried replacing the code as stated above; nothing seemed to change however. I did not get an output to the serial (TeraTerm) listing the files on the SDcard.

When I disbalelun() and the disk becomes and an inaccessible state, I should be able to read files correct?

Thanks for the help

Got it!! Thanks!

Good! So what is the final version of the code that worked for you?