EMX as PC mass storage

I use this(code below), the PC nicely enumerates the device, and I can copy files. But if I unplug it from the PC and plug it back in then it comes up as an unknown device. Is there any unload functions I have to call somewhere.

static void DeviceConnectedEvent(USBH_Device device)
        {
            if (device.TYPE == USBH_DeviceType.MassStorage)
            {
                DispPrint("USB MS Detected");

                ps = new PersistentStorage(device);

                if (MicEWR.GetEthernetEnable() == 2)
                {
                    ms = USBClientController.StandardDevices.StartMassStorage();
                    ms.AttachLun(0, ps, " ", " ");

                    Storage.ms.EnableLun(0);
                    DispPrint("USB MS Ready");

lets start with the housekeeping - welcome to the forums, I see this is your first post. In future, please use the CODE button to show your code in a nice format :slight_smile:

How are you powering the device? Plug-pack, or just USB? i.e. does the system reset when you plug/unplug it?

Do you have a Device Disconnected event handler? If not, you should look into what that does and what it needs to do (to properly handle the close etc) and you may find that since the connected handler creates a new persistent storage handler if it fires on a 2nd pass that will fail since it already exists?

My final comment is - Debug! What is debugging and stepping through the code telling you?

I am active on the GHI forum…since you folks have a link there to migrate to this link. I created an account here today…I will post the code the right way next time

How are you powering the device? Plug-pack, or just USB? i.e. does the system reset when you plug/unplug it?
Power plug. System does not reset during plug/unplug.

Do you have a Device Disconnected event handler? If not, you should look into what that does and what it needs to do (to properly handle the close etc) and you may find that since the connected handler creates a new persistent storage handler if it fires on a 2nd pass that will fail since it already exists?

May be I confused you. I am using the USB Device not the USB host functionality.
So the USB mass storage is always plugged in. At power up, the DeviceConnectedEvent does Storage.ms.EnableLun(0); => as shown in my code, which I coped from your example.
Then nothing else is done the thread sleeps.

When the USH device is plugged/unplugged into the PC. I do not need to do anything it is handelled by Microsoft or GHI.

My final comment is - Debug! What is debugging and stepping through the code telling you?

Debug does not tell anything

Please don’t post on both forum. It is hard to keep track that way.

This should be working fine.
Please make a small project that only enables the USB MS, do you see any problems? Please provide code.