UsbClient 4.3 documentation?

DLL version GHI is 4.3.3 and MS is 4.3.1 is this correct?

@ David@ Emrol -

Can you please use a different SD or try to format that SD?

If you are using FEZ CorbaII then the connection should be OK (no wire needed) but if using a FEZ Spider II or custom board, make sure the connection board and SD is good.

If i deploy my main application to the custom board then this is reading startup config from this SD and logged data to SD so connection should be ok.

To be 100% sure i just put a brand new quality SD in but same result.

More things that i can check?

@ David@ Emrol -

I just ran your code with a bit modified. Yes, sometime I see the exception same as you. But it work fine without VS debugger (I just press Reset button).

But in my old code, it works fine.

Can you please try my code (just copy and paste) or deploy code below and run without VS

   public static void Main()
        {
            GHI.Usb.Client.MassStorage MyUSBClient;
            GHI.IO.Storage.SDCard MySD;
            MySD = new GHI.IO.Storage.SDCard();
            MyUSBClient = new GHI.Usb.Client.MassStorage(0x1B9F, 0xF002, 0x100, 250, "TriNeuron", "MFC", "123456", "xyz", 1);
            GHI.Usb.Client.Controller.ActiveDevice = MyUSBClient;
            Thread.Sleep(100);
            MyUSBClient.AttachLogicalUnit(MySD, 0, " ", " ");
            Thread.Sleep(100);
            MyUSBClient.EnableLogicalUnit(0);
            Thread.Sleep(-1);

        }

Correct! if i press reset then the SD get’s mounted, from VS i have the error.
Is your original sample running when deployed from VS?
If so then i have a deeper look at this code.

@ Dat - I tried your sample code but in debug mode i have the same error.
If i reboot the custom board with code bellow the SD gets mounted.
However i copy that exact lines in my main program it fails.

More ideas?


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

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

using GHI.IO;
using GHI.Usb;
using GHI.Usb.Host;
using GHI.Processor;
using GHI.IO.Storage;
using GHI.Usb.Client;

namespace G120_Lun
{
    public class Program
    {
        private static SDCard _sd;
        private static GHI.Usb.Host.MassStorage _usb;
        private static GHI.Usb.Client.MassStorage _ms = null;
        private static InputPort ldr1 = new InputPort((Cpu.Pin)(22), false, Port.ResistorMode.PullUp); // PA4 - LDR1
        private static OutputPort led = new OutputPort((Cpu.Pin)(47), true);// PD3 led

        public static void Main()
        {
            led.Write(true);
            GHI.Usb.Host.Controller.MassStorageConnected += Controller_MassStorageConnected;
            GHI.Usb.Host.Controller.Start();
      
             // For SD, I tested on FezcorbaII
             while (ldr1.Read())
             {
                 Thread.Sleep(50);
                 led.Write(true);
                 Thread.Sleep(50);
                 led.Write(false);
             }

             _sd = new SDCard();

            Thread.Sleep(100);
            _ms = new GHI.Usb.Client.MassStorage(0x1B9F, 0xF002, 0x100, 250, "GHI Electronics", "Mass Storage", null, "Mass Storage", 1);
            GHI.Usb.Client.Controller.ActiveDevice = _ms;
            Thread.Sleep(100);
            _ms.AttachLogicalUnit(_sd,0 , " ", " ");
            Thread.Sleep(100);
            _ms.EnableLogicalUnit(0);
            Thread.Sleep(100);

            while (true)
            {
                led.Write(true);
                Thread.Sleep(200);
                led.Write(false);
                Thread.Sleep(200);
            }
        }

        static void Controller_MassStorageConnected(object sender, GHI.Usb.Host.MassStorage e)
        {
            _usb = e;
            detectUsbconnected = true;
        }
        static bool detectUsbconnected = false;
    }
}

@ David@ Emrol -

See, now I can reproduce with VS in my side. I will find if there is any workaround.

I have been playing some more in my main application and have different errors if i change the sleep time at the marked line bellow:


                        //4.3 connect only once !
                        if (USBControllers[0].Status == Microsoft.SPOT.Hardware.UsbClient.UsbController.PortState.Running && MyUSBClientLoaded == 0)
                        {
                            // only if SD is active
                            if (SDStorage != 0 )
                            {
                                // flag 
                                MyUSBClientLoaded = 1;

                                // log naar syslog
                                SysLogFileWriteLine(RealDateTime + " : " + "USB Client connected");

                                // still mounted -> close all file handles
                                FreeSDcard();
                                Thread.Sleep(50);
                                MySD.Unmount();  

                                while (MySD.Mounted == true)
                                {
                                    Debug.Print("waiting on release SD...");
                                    Thread.Sleep(50);
                                }

                                try
                                {
                                    //4.3
                                    MyUSBClient = new GHI.Usb.Client.MassStorage(0x1B9F, 0xF002, 0x100, 250, "TriNeuron", "MFC", "", "", 1);
                                    Thread.Sleep(100);   // <<<<<<-------- THIS SLEEP TIME
                                    GHI.Usb.Client.Controller.ActiveDevice = MyUSBClient;
                                    Thread.Sleep(100);
                                    MyUSBClient.AttachLogicalUnit(MySD, 0, " ", " ");
                                    Thread.Sleep(100);
                                    MyUSBClient.EnableLogicalUnit(0);
                                }
                                catch
                                {
                                    MyUSBClientLoaded = 0;
                                    SysLogFileWriteLine(RealDateTime + " : " + "Error at attachlun(0) and µSD");
                                }
                            }
                        }

I first noticed different errors if i was stepping in code or moved my breakpoints.
With the 100ms sleep if have this error:


    #### Exception System.ArgumentOutOfRangeException - CLR_E_OUT_OF_RANGE (4) ####
    #### Message: 
    #### System.Collections.ArrayList::get_Item [IP: 0000] ####
    #### System.IO.FileSystemManager::ForceRemoveNameSpace [IP: 0026] ####
    #### Microsoft.SPOT.IO.RemovableMedia::MessageHandler [IP: 005c] ####
A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll

If i increase the sleep time to 1000ms i have:


    #### Exception System.InvalidOperationException - CLR_E_INVALID_OPERATION (8) ####
    #### Message: 
    #### GHI.Usb.Client.Controller::NativeStart [IP: 0000] ####
    #### GHI.Usb.Client.Controller::set_ActiveDevice [IP: 0018] ####
    #### IRC.Program::WDTCounterResetLoop [IP: 0151] ####
A first chance exception of type 'System.InvalidOperationException' occurred in GHI.Usb.dll
An exception of type 'System.InvalidOperationException' occurred in GHI.Usb.dll and wasn't handled before a managed/native boundary

Annyone has a deeper knowledge understanding what’s the possible root cause?
The fact that deppending on delay the error ocures in a different dll makes me think there is still some init process running but i dont see a way to check a “ready” state in a delayed loop…